jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 如何在jQuery Mobile中动态设置’data-collapsed’和’data-theme’?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在运行时动态设置’data-theme’和’data-collapsed’时遇到问题,我用过:

$(SELEctor).attr('data-collapsed',falsE)

$(SELEctor).attr('data-theme',b)

但它不起作用,如何使用jQuery或javascript解决这个问题?

解决方法

你可以使用pagebeforecreate事件

> http://jquerymobile.com/test/docs/api/events.html

例:

> http://jsfiddle.net/ayEWB/

JS

$('#home').live('pagebeforecreate',function(event) {
    var col = $('#collapseMe');

    // Alternative setTings
    //col.attr('data-collapsed','false');
    //col.attr('data-theme','b');

    col.data('collapsed',falsE);
    col.data('theme','b');
});

HTML

<!DOCTYPE html>
<html class="ui-mobile-rendering">
<head>
    <Meta charset="utf-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1">
    <title>jQuery Mobile: Demos and Documentation</title>
    <link rel="stylesheet"  href="http://jquerymobile.com/test/css/themes/default/jquery.mobile.css" />

    <script src="http://jquerymobile.com/test/js/jquery.js"></script>
    <script src="http://jquerymobile.com/test/js/jquery.mobile.js"></script>

</head>
<body>
<div data-role="page" id="home">
    <div data-role="content">
        <div data-role="collapsible" data-theme="a" data-content-theme="a" id="collapseMe">
           <h3>Header swatch A</h3>
           <p>I'm the collapsible content with a themed content block set to "A".</p>
        </div>
    </div>
</div>
</body>
</html>
​

大佬总结

以上是大佬教程为你收集整理的javascript – 如何在jQuery Mobile中动态设置’data-collapsed’和’data-theme’?全部内容,希望文章能够帮你解决javascript – 如何在jQuery Mobile中动态设置’data-collapsed’和’data-theme’?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。