【问题标题】:jQueryMobile: Button action not getting calledjQueryMobile:未调用按钮操作
【发布时间】:2012-12-26 06:30:08
【问题描述】:

下面的代码尝试在 jQueryMobile 中实现按钮操作,但它对我不起作用。请让我知道我错在哪里。一切都写在 HTML 文件中。 我在这里提供我的代码时遇到了一些问题。这是我正在尝试的。 在标准的 HTML 格式中,我在 script 标签之间编写以下代码

$('#theButton').click(function() {
   alert('The Button has been clicked,');

});

并且在body标签中---

<div data-role="page">
<div data-role="content">
    <input type="button" id="theButton" name="theButton" value="The Button">
</div>

但没有调用该操作。

【问题讨论】:

  • 还有更多的代码吗? jQuery Mobile 工作正常吗?脚本片段是否真的在运行?我们怎么知道没有错误阻止事件被绑定?你有没有打开控制台,所以你可以说没有错误?
  • 亲爱的@popnoodles:请参考下面的答案
  • 是你的代码,还是不行吗?
  • @popnoodles:代码有效,我已接受答案(见绿色复选标记)。

标签: jquery-mobile


【解决方案1】:

编辑:请尝试以下代码:

<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

<script language="javascript">

    $(function() {
     $('#theButton').on('tap click',function(event, ui) {
        alert('The Button has been clicked');
     });
    });

</script>
</head>
<body>
<div data-role="page">
<div data-role="content">
    <input type="button" id="theButton" name="theButton" value="The Button">
</div>
</div>
</body>
</html>

【讨论】:

  • 亲爱的@naoki,我正在尝试一个简单的按钮操作示例,但它不起作用。我想我缺少一个非常基本的元素。
  • 感谢@naoki 的快速帮助。:) 非常感谢。
  • @naoki- 当我在 iPhone 模拟器(Safari 浏览器)中运行文件时,警报显示:file://(null)。有什么想法吗?
  • 抱歉,我不确定为什么它会发生在 iPhone 模拟器上。你的代码和上面一样吗?
  • 是啊!。而不是在网络浏览器中运行它,我在移动 safari 中运行。无论如何谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-26
  • 2013-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多