Jquery mobile Jquery移动、可折叠集和子对象

Jquery mobile Jquery移动、可折叠集和子对象,jquery-mobile,accordion,Jquery Mobile,Accordion,我正在尝试动态填充JQM手风琴/可折叠集的内容。我已经看过了,但是这些例子似乎已经过时了。因此,我试图提出一个可行的例子,但我目前陷入困境,看不出为什么这不可行: <script type="text/javascript"> $(document).ready(function() { $(".mySet").bind('expand', function (event, ui) { /* This prints e.g. "This is the firs

我正在尝试动态填充JQM手风琴/可折叠集的内容。我已经看过了,但是这些例子似乎已经过时了。因此,我试图提出一个可行的例子,但我目前陷入困境,看不出为什么这不可行:

<script type="text/javascript">
$(document).ready(function() {
    $(".mySet").bind('expand', function (event, ui) {
        /* This prints e.g. "This is the first entry\n
        I'm the collapsible set content for section 1." */
        console.log($(this).text());

        /* This should print "This is the first entry" (=the innerText of <h3>)
        but it doesn't, it prints "This is the first entry\n
        I'm the collapsible set content for section 1." as well */
        console.log($(this).next().text());

        /* This should just print "I'm the collapsible set content for section 1"
        (=the innerText of <p>) but it doesn't, it prints e.g. "This is the 
        first entry\n I'm the collapsible set content for section 1." as well */
        console.log($(this).nextAll("p").text());
    });
});
</script>

<div data-role="collapsible-set">
    <div data-role="collapsible" class="mySet">
        <h3>This is the first entry</h3>
        <p>I'm the collapsible set content for section 1.</p>
    </div>
    <div data-role="collapsible" class="mySet">
        <h3>This is the second entry</h3>
        <p>I'm the collapsible set content for section 2.</p>
    </div>
</div>

$(文档).ready(函数(){
$(“.mySet”).bind('expand',函数(事件,用户界面){
/*这将打印例如“这是第一个条目\n
我是第一节的可折叠集合内容。”*/
console.log($(this.text());
/*应打印“这是第一个条目”(=的内部文本)
但它没有,它打印“这是第一个条目\n
我也是第1节的可折叠集合内容*/
log($(this.next().text());
/*这应该只是打印“我是第1节的可折叠集合内容”
(=的内部文本)但它没有,它打印例如“这是
第一项\n我也是第1节的可折叠集合内容*/
log($(this.nextAll(“p”).text());
});
});
这是第一个条目
我是第一节的可折叠集合内容

这是第二个条目 我是第2节的可折叠集合内容

有人看到了吗,为什么jQuery不会下降到
$(这个)
(=它指向当前扩展的
?如果我在Opera的DragonFly中调试这个代码,我可以看到,
$(这个)
似乎与
$(这个)相同。next()
(至少它们对于innerHTML等具有相同的值)


谢谢你的帮助!

因此,在稍微调整一下之后,我想出了以下解决方法:

$(document).ready(function() {
    $(".mySet").bind('expand', function (event, ui) {
        /* I'm just creating a new var "myDiv" which points to my current div (so in a 
        way "myDiv" is just a copy of "this" */
        var myDiv = $("#"+$(this).attr('id'));
        var myP = myDiv.find('p:first');

        // Works as expected, prints "I'm the collapsible set content for section 1."
        console.log(myP.text());
    });
});