gpt4 book ai didi

jquery-mobile - 无法获取要执行的 JQuery-Mobile 可折叠展开/折叠事件

转载 作者:行者123 更新时间:2023-12-04 06:00:11 28 4
gpt4 key购买 nike

我有以下演示 HTML 文件,我想使用 JQuery-Mobile 可折叠展开/折叠事件,但我无法触发 JavaScript 事件。我在这里基于 JSFiddle 示例:http://jsfiddle.net/6txWy/

我觉得我只是忽略了一些简单的东西,但这是我的 HTML 文件:

<html> 
<head>
<title>References</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<link rel="stylesheet" href="css/main.css" />

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

<script type="text/javascript">
$('#my-collaspible').bind('expand', function()
{
alert('Expanded');
}).bind('collapse', function () {
alert('Collapsed');
});
</script>
</head>

<body>
<div data-role="page">
<div data-role="content">
<div data-role="collapsible" id="my-collaspible">
<h3>My Title</h3>
<p>My Body</p>
</div>
</div>
</div>
</body>
</html>

折叠和展开有效,但永远不会触发警报。

谢谢!跳蚤

最佳答案

添加 PageInit在绑定(bind)事件之前调用以确保页面已加载

例子:

代码:

$('#home').live('pageinit', function(event) {
$('#my-collaspible').bind('expand', function() {
alert('Expanded');
}).bind('collapse', function() {
alert('Collapsed');
});
});

关于jquery-mobile - 无法获取要执行的 JQuery-Mobile 可折叠展开/折叠事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10819817/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com