【问题标题】:Jquery Mobile, how to collapse a collapsible after link has been clicked? JfiddleJquery Mobile,单击链接后如何折叠可折叠?提琴手
【发布时间】:2017-06-11 11:36:09
【问题描述】:

我的目标是让数据角色可折叠,在我单击选项卡链接后折叠。有没有解决方案或更好的方法来解决这个问题?谢谢。

这是我的小提琴,注意标签发生了变化,但可折叠部分保持打开状态,我尝试使用点击功能,但它似乎没有做任何事情。

有什么想法吗?

Jfiddle

HTML

<div data-role="tabs">
  <div class="filter" data-role="collapsible" data-iconpos="right" data-collapsed-icon="carat-d" data-expanded-icon="carat-u">
    <h4>Filter</h4>
    <ul data-role="listview" data-inset="false" >
         <li><a class="collapse" href="#one" data-ajax="true">Suggested</a></li>
        <li><a  href="#two" data-ajax="false">Distance</a></li>
        <li><a href="#three" data-ajax="false">Rating</a></li>
        <li><a href="#four" data-ajax="false">Open Now</a></li>
        <li><a href="five" data-ajax="false">Test</a></li>
    </ul>
</div> 

    <div id="one" class="tablist-content">

 <!-- TAB 1  --->
 1<br>1<br>1<br>1<br>1<br>1<br>

  </div>
    <div id="two" class="tablist-content" >

        <!-- TAB 2  --->
   2<br>2<br>2<br>2<br>2<br>2<br>2<br> 

    </div>
     <div id="three" class="tablist-content" >

        <!-- TAB 3  --->
   3<br>3<br>3<br>3<br>3<br>3<br>3<br>

    </div>   
      <div id="four" class="tablist-content" >

        <!-- TAB 4  --->
   4<br>4<br>4<br>4<br>4<br>


    </div>  

</div>  

脚本

$(document).ready(function() {  

    $(".collapse").click(function() {
        console.log("ok");
        $( ".filter" ).trigger( "collapse" );
    });

});

<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  

【问题讨论】:

    标签: javascript jquery html jquery-mobile


    【解决方案1】:

    这里有两个问题。首先,您加载了两个版本的 jQuery。

    https://code.jquery.com/jquery-1.11.3.min.js

    https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js

    这可能会产生冲突,所以请移除一个。

    其次,折叠的正确代码是:

    $( ".filter" ).collapsible( "collapse" );
    

    【讨论】:

    • 非常感谢,我认为我需要第二个脚本来执行地理定位功能,但我删除了第二个脚本并将函数放在标题中。现在可以了。
    猜你喜欢
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2012-11-21
    • 1970-01-01
    • 2016-02-28
    • 2013-05-29
    • 1970-01-01
    相关资源
    最近更新 更多