所以我有这个代码,应该听取#button的点击但是它不起作用,并且让我发疯了!
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$('#button').click(function() {
alert('OK!');
});
</script>
和HTML:
<input id="button" type="button" value="OK" />
这很奇怪。欢迎任何帮助!
答案 0 :(得分:15)
在document.ready function
中编写代码<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#button').click(function() {
alert('OK!');
});
});
</script>
OR
<script type="text/javascript">
function on_click() {
alert("OK !!");
}
$(document).ready(function() {
$("#button").click(on_click);
});
</script>
希望你能从中得到一些想法
答案 1 :(得分:2)
以下是代码的样子:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript">
// Now that jquery is include, place the code to wire up the button here
$(function(){
// Once the document.onload event fires, attach the click
// event handler for the button
$('#button').click(function() {
alert('OK!');
});
});
</script>
<input id="button" type="button" value="OK" />
这是与此相关的jquery文档: http://docs.jquery.com/How_jQuery_Works