更改可折叠菜单标题中的文本会使其消失

时间:2012-07-31 22:04:50

标签: javascript jquery html jquery-mobile cordova

我正在尝试创建一个将数据存储在一系列可折叠菜单中的应用程序。首先是几个月的菜单,然后是月内的日子,然后是日内的时间,然后是时间内的数据。我需要菜单的标题能够根据用户输入的时间和日期进行更改,但如果我更改标题文本,则菜单会丢失其图形而只是变为文本。单击它时会显示可折叠的内容,但不会触发可折叠的onclick事件。给出的大多数html代码都是由Codiqa生成的。如何使这项工作正确?

带可折叠的html页面:

<!-- Logs -->
    <div data-role="page" data-theme="a" id="page15">
        <div data-theme="a" data-role="header">
            <h3>
                Logs
            </h3>
            <a data-role="button" data-direction="reverse" data-transition="slide" href="#page3" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                Back
            </a>
        </div>
        <div data-role="content" style="padding: 15px">
            <a data-role="button" data-transition="slide" href="#page1">
                Add log entry
            </a>
            <div data-role="collapsible-set" data-theme="" data-content-theme="">
                <div data-role="collapsible" data-collapsed="true">
                    <h3>
                        July 2012
                    </h3>
                    <div data-role="collapsible-set" data-theme="" data-content-theme="">
                        <div data-role="collapsible" data-collapsed="true" onclick="getLogTime(); this.onclick=null">
                            <h3>
                                July 5
                            </h3>
                            <div data-role="collapsible-set" data-theme="" data-content-theme="">
                                <div data-role="collapsible" data-collapsed="true" onclick="getLogData(); this.onclick=null">
                                    <h3 id=time1>//Heading in question
                                    </h3>
                                    <div>
                                        <p id="logFortime1">
                                        Log 1
                                        </p>
                                    </div>
                                </div>
                                <div data-role="collapsible" data-collapsed="true">
                                    <h3>
                                        12:47 pm
                                    </h3>
                                </div>
                            </div>
                        </div>
                        <div data-role="collapsible" data-collapsed="true">
                            <h3>
                                July 6
                            </h3>
                        </div>
                    </div>
                </div>
                <div data-role="collapsible" data-collapsed="true">
                    <h3>
                        August 2012
                    </h3>
                </div>
            </div>
            <a data-role="button" data-transition="slide" href="#page21">
                Graphs
            </a>
        </div>
    </div>

更改标题的功能:

function getLogTime() {
    $('#time1').html('Time');
}

编辑:

在约瑟夫·马里克尔(Joseph Marikle)提到的id=time1附近添加了“”,修复了不触发的onclick事件,但仍然没有显示可折叠的图形。

编辑:

由Codiqa生成的css:

/* Generic icon styles */

/* 26x26 pixels */

.ui-btn-icon-left .ui-btn-inner .ui-icon.ui-iconsize-26, 
.ui-btn-icon-right .ui-btn-inner .ui-icon.ui-iconsize-26 {
margin-top: -13px;
}

.ui-btn-icon-notext .ui-icon { display: block; z-index: 0;}

.ui-btn-icon-top .ui-btn-inner .ui-icon.ui-iconsize-26, .ui-btn-icon-bottom .ui-btn-inner .ui-icon.ui-iconsize-26 { position: absolute; left: 50%;  margin-left: -13px; }
.ui-header .ui-btn-icon-left .ui-icon.ui-iconsize-26,
.ui-footer .ui-btn-icon-left .ui-icon.ui-iconsize-26,
.ui-mini.ui-btn-icon-left .ui-icon.ui-iconsize-26,
.ui-mini .ui-btn-icon-left .ui-icon.ui-iconsize-26 { left: 3px; margin-top: -12px; }

.ui-header .ui-btn-icon-right .ui-icon.ui-iconsize-26,
.ui-footer .ui-btn-icon-right .ui-icon.ui-iconsize-26,
.ui-mini.ui-btn-icon-right .ui-icon.ui-iconsize-26,
.ui-mini .ui-btn-icon-right .ui-icon.ui-iconsize-26 { right: 3px; margin-top: -12px; }

.ui-header .ui-btn-icon-top .ui-icon.ui-iconsize-26,
.ui-footer .ui-btn-icon-top .ui-icon.ui-iconsize-26,
.ui-mini.ui-btn-icon-top .ui-icon.ui-iconsize-26,
.ui-mini .ui-btn-icon-top .ui-icon.ui-iconsize-26 { top: 3px; }

.ui-header .ui-btn-icon-bottom .ui-icon.ui-iconsize-26,
.ui-footer .ui-btn-icon-bottom .ui-icon.ui-iconsize-26,
.ui-mini.ui-btn-icon-bottom .ui-icon.ui-iconsize-26,
.ui-mini .ui-btn-icon-bottom .ui-icon.ui-iconsize-26 { bottom: 3px; }




.ui-icon-ios-pack-color-left-arrow {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-right-arrow {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-up-arrow {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-back {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-forward {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-down-arrow {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
   border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-plus {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
 -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-minus {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-check {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-delete {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-gear {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-refresh {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-grid {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-star {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-info {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-home {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-search {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}

.ui-icon-ios-pack-color-alert {
  width: 26px;
  height: 26px;
  background-color: transparent !important;
  box-shadow: none;
  -moz-box-shadow: none;
  -ms-box-shadow: none;
  -o-box-shadow: none;
  -webkit-box-shadow: none;
  border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
}





.ui-icon-ios-pack-color-left-arrow {
  background: url('images/ios-pack-color.png') -260px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-right-arrow {
  background: url('images/ios-pack-color.png') -364px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-up-arrow {
  background: url('images/ios-pack-color.png') -442px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-back {
  background: url('images/ios-pack-color.png') -26px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-forward {
  background: url('images/ios-pack-color.png') -130px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-down-arrow {
  background: url('images/ios-pack-color.png') -104px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-plus {
  background: url('images/ios-pack-color.png') -312px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-minus {
  background: url('images/ios-pack-color.png') -286px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-check {
  background: url('images/ios-pack-color.png') -52px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-delete {
  background: url('images/ios-pack-color.png') -78px 50% no-repeat transparent     !important;
}

.ui-icon-ios-pack-color-gear {
  background: url('images/ios-pack-color.png') -156px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-refresh {
  background: url('images/ios-pack-color.png') -338px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-grid {
  background: url('images/ios-pack-color.png') -182px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-star {
  background: url('images/ios-pack-color.png') -416px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-info {
  background: url('images/ios-pack-color.png') -234px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-home {
  background: url('images/ios-pack-color.png') -208px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-search {
  background: url('images/ios-pack-color.png') -390px 50% no-repeat transparent !important;
}

.ui-icon-ios-pack-color-alert {
  background: url('images/ios-pack-color.png') -0px 50% no-repeat transparent !important;
}


@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
       only screen and (min--moz-device-pixel-ratio: 1.5),
       only screen and (min-resolution: 240dpi) {

  .ui-icon-ios-pack-color-left-arrow,.ui-icon-ios-pack-color-right-arrow,.ui-icon-ios-pack-color-up-arrow,.ui-icon-ios-pack-color-back,.ui-icon-ios-pack-color-forward,.ui-icon-ios-pack-color-down-arrow,.ui-icon-ios-pack-color-plus,.ui-icon-ios-pack-color-minus,.ui-icon-ios-pack-color-check,.ui-icon-ios-pack-color-delete,.ui-icon-ios-pack-color-gear,.ui-icon-ios-pack-color-refresh,.ui-icon-ios-pack-color-grid,.ui-icon-ios-pack-color-star,.ui-icon-ios-pack-color-info,.ui-icon-ios-pack-color-home,.ui-icon-ios-pack-color-search,.ui-icon-ios-pack-color-alert {
    background-image: url('images/ios-pack-color@2x.png');
    -moz-background-size: 468px 26px;
    -o-background-size: 468px 26px;
    -webkit-background-size: 468px 26px;
    background-size: 468px 26px;
  }

}


.text-align-center {
  text-align: center;
}
.text-align-right {
  text-align: right;
}

/** CSS for non-standard jQuery Mobile styles or Codiqa components **/
.split-wrapper {
  width: 100%;
  min-height: 200px;
  clear: both;
}
@media all and (min-width: 650px) {
    .content-secondary {
        text-align: left;
        float: left;
        width: 45%;
        background: none;
        padding: 1.5em 6% 3em 0;
        margin: 0;
    }
    .content-secondary {
    background: none;
    border-top: none;
    }
    .content-primary {
        width: 45%;
        float: right;
        margin-right: 1%;
        padding-right: 1%;
    }
    .content-primary ul:first-child {
        margin-top: 0;
    }
  .content-secondary ul.ui-listview, .content-secondary ul.ui-listview-inset {
    margin: 0;
  }
  .content-secondary ul.ui-listview .ui-li-divider, .content-secondary ul.ui-listview         .ui-li {
    border-radius: 0px;
  }
  .content-secondary ul.ui-listview .ui-li {
    border-left: 0;
    border-right: 0;
  }
    .content-secondary h2 {
        position: absolute;
        left: -9999px;
    }
    .content-secondary .ui-li-divider {
        padding-top: 1em;
        padding-bottom: 1em;
    }
    .content-secondary {
        margin: 0;
        padding: 0;
    }

}
@media all and (min-width: 750px){
    .content-secondary {
        width: 34%;
    }
    .content-primary {
        width: 60%;
        padding-right: 1%;
    }   
  .content-secondary ul.ui-listview-inset {
}

@media all and (min-width: 1200px){
    .content-secondary {
        width: 30%;
        padding-right:6%;
        margin: 0px 0 20px 5%;
    }
    .content-secondary ul {
    margin: 0;
  }
    .content-secondary {
        margin: 0;
        padding: 0;
    }
    .content-primary {
        width: 50%;
        margin-right: 5%;
        padding-right: 3%;
    }
    .content-primary {
        width: 60%;
    }
}

html文件也使用<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.0/jquery.mobile-1.1.0.min.css" />

1 个答案:

答案 0 :(得分:1)

我想我已经弄明白是什么导致了你的问题。我的演示linked above确实重现了问题

  

点击
  2012年7月 - &gt; 7月5日&gt; //标题 - &gt;日志1

您遇到的问题是由您使用的移动库引起的。使用此库时,它会更改HTML将子元素添加到现有元素。因此,当您更改元素的HTML时,它会彻底改变样式。您需要做的是找到放置文本的位置。根据我的观察,似乎可以在ui-btn-text类的元素中找到该文本。从那里开始就像在代码中更改选择器一样简单(我还使用text代替html):

function getLogTime() {
    $('#time1 .ui-btn-text').text('Time');
}

您可以在the working version of my demosource

中看到它

如果您有任何问题,请发表评论。