Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
点击jQuery移动可折叠集?_Jquery_Jquery Mobile_Click - Fatal编程技术网

点击jQuery移动可折叠集?

点击jQuery移动可折叠集?,jquery,jquery-mobile,click,Jquery,Jquery Mobile,Click,如何绑定可折叠集合中的一个元素 <div data-role="content"> <div data-role="collapsible-set" data-theme="d" data-content-theme="d"> <div data-role="collapsible" id="expand"> <h3>header</h3> </div> </di

如何绑定可折叠集合中的一个元素

<div data-role="content">
   <div data-role="collapsible-set" data-theme="d" data-content-theme="d">
       <div data-role="collapsible" id="expand">
        <h3>header</h3>
       </div>
   </div>
</div>

演示:

由于jQuery Mobile增强功能,当您单击标题时,似乎不会触发绑定到click事件的操作。 一个选项(我承认不是很漂亮)是在JQM增强后将事件绑定到适当的DOM元素。如果您确实打算防止默认行为(这将防止可折叠文件被拆开!),您可以使用如下代码:

$(document).on('pageinit',function (f) {
  //pageinit event is triggered after the page is initialized

    $("#expand").find("*").click(function (e) {
      //apply to all descendant of your element "#expand a" selector would be sufficient to cover the header
         e.stopImmediatePropagation();
         e.preventDefault();
     console.log('ekb');
    });
});

结果是可见的

它似乎工作正常。您希望它做什么?它不显示console.log单击“hh”部分会在osx中的chrome浏览器中的safari和safari中都记录“ekb”。您使用的是什么操作系统/浏览器?您的小提琴很好。它显示了控制台。登录到chrome。我需要它按标题单击
$(document).on('pageinit',function (f) {
  //pageinit event is triggered after the page is initialized

    $("#expand").find("*").click(function (e) {
      //apply to all descendant of your element "#expand a" selector would be sufficient to cover the header
         e.stopImmediatePropagation();
         e.preventDefault();
     console.log('ekb');
    });
});