JQuery调⽤绑定click事件的3种写法
第⼀种⽅式:
$(document).ready(function(){
$("#clickme").click(function(){
alert("Hello World click");
});
第⼆种⽅式:
$('#clickmebind').bind("click", function(){
alert("Hello World bind");
});
第三种⽅式:
$('#clickmeon').on('click', function(){
alert("Hello World on");
});
});
注意:第三种⽅式只适⽤于jquery 1.7以上的版本
源码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="adata.js"></script>
<script type="text/javascript" src="js/messages_zh.js"></script>
<style type="text/css">
# {
color: Red;
}
</style>
</head>
<script type="text/javascript">
$(document).ready(function(){
$("#clickme").click(function(){
alert("Hello World click");
});
$('#clickmebind').bind("click", function(){
alert("Hello World bind");
});
$('#clickmeon').on('click', function(){
alert("Hello World on");
});
});
</script>
<body>
<label></label>
<form id="frm" name="frm" method="post" action=""><label>⽤户名:
<input type="text" name="username" id="username" />
</label>
<p>
<label>邮编 :<label></label></label>
<label>
<input type="text" name="postcode" id="postcode" />
<br />
</label>
</p>
<p><label>数字 :
<input type="text" name="number" id="number" />
</label>
<br /><label>⾝份证号:
<input type="text" name="identifier" id="identifier" />
</label>
<label>
<input type="button" name="clickme" id="clickme" value="click me" />
</label>
jquery源码在线
<label>
<input type="button" name="clickmebind" id="clickmebind" value="clickme_bind" /> </label>
<label>
<input type="button" name="clickmeon" id="clickmeon" value="clickme_on" />
</label>
</p>
</form>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论