Jquery Mobile:动态更改可折叠div的标题文本?
Place:
如何在可折叠div中动态更改
标题(’Place:’)的文本?
我试过了:
$('#collapsePlace').children('h3').text('new text');
它改变了文本 – 但失去了所有的造型!
jQuery Mobile 1.0RC2中可折叠的实际HTML结构如下(在框架对HTML传递之后):
元素中的嵌套
元素使这有点棘手。 如果要保留
元素的结构,则需要保存嵌套的
元素,覆盖它,然后替换它:
//run code on document.ready $(function () { var num = 1; //add click handler to link to increment the collapsible's header each click $('a').bind('click', function () { //cache the `` element and its child var $btn_text = $('#collapsePlace').find('.ui-btn-text'), $btn_child = $btn_text.find('.ui-collapsible-heading-status'); //overwrite the header text, then append its child to restore the previous structure $btn_text.text('New String (' + num++ + ')').append($btn_child); }); });
这是上述解决方案的一个方面: http : //jsfiddle.net/jasper/4DAfn/2/
在1.3.2中,以下似乎有效:
My Header
JQuery的:
$("#MyID h3 #MyHeaderID").text("Your New Header");
快乐的编码!
一个简单的解决方案就是
$('#collapsePlace .ui-btn-text').text("hello ");
查看http://jsfiddle.net/AQZQs/1/上的小提琴
一个简单的选择是给h3一个自定义id / class,例如:
Place:
那样你只需要这样做:
$('#collapsePlace #h3Text').text('new text');