这段代码有什么问题?
<!DOCTYPE html>
<html>
<head>
<title>WebService Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="jquery.mobile-1.0.1.min.css" />
<script src="jquery.js"></script>
<script src="jquery.mobile-1.0.1.min.js"></script>
<script type="text/javascript">
$("#Btn").click(function (event) {
alert("Button Clicked");
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-nobackbtn="false">
<div><a href="index.html">Back</a></div>
</div>
<div data-role="content">
This is the content
</div>
<div data-role="footer">
<a href="#" data-role="button"
data-icon="info" id="Btn">Button</a>
</div>
</div>
</body>
最佳答案
代码在 DOM 准备好之前运行。将其放入 DOM 中 ready
事件处理程序:
$(document).ready(function() {
//Code that interacts with the DOM (such as binding event listeners...)
$("#Btn").click(function (event) {
alert("Button Clicked");
});
});
关于jQuery 按钮没有被点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9783202/