为什么 class.click 方法不起作用?
Why the class.click method doesn't work?
我是网络编程的初学者。我正在尝试将 click 方法分配给类名。但它不起作用,互联网上没有任何解决方案对我有用。我该如何解决这个问题?
我的简单代码:
<html>
<head>
<title>ada</title>
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>
添加jquery库文件
http://code.jquery.com/jquery-1.8.3.min.js
$(document).on("click",".menu",function()
{
alert("Hello World");
});
<html>
<head>
<title>ada</title>
**<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>**
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>
第一。确保您在 head 元素的脚本标记中引用了 Jquery api。
第二。一个很好的教程和易于阅读的初学者参考
http://www.w3schools.com/jquery/event_click.asp
我是网络编程的初学者。我正在尝试将 click 方法分配给类名。但它不起作用,互联网上没有任何解决方案对我有用。我该如何解决这个问题?
我的简单代码:
<html>
<head>
<title>ada</title>
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>
添加jquery库文件
http://code.jquery.com/jquery-1.8.3.min.js
$(document).on("click",".menu",function()
{
alert("Hello World");
});
<html>
<head>
<title>ada</title>
**<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>**
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>
第一。确保您在 head 元素的脚本标记中引用了 Jquery api。
第二。一个很好的教程和易于阅读的初学者参考 http://www.w3schools.com/jquery/event_click.asp