简要咨询咨询QQ网站导航网站搜索手机站点联系我们设为首页加入收藏 

JQuery调用绑定click事件的3种写法

来源:易贤网   阅读:1276 次  日期:2015-04-02 16:27:19

温馨提示:易贤网小编为您整理了“JQuery调用绑定click事件的3种写法”,方便广大网友查阅!

这篇文章主要介绍了JQuery调用绑定click事件的3种写法,本文简洁清晰的给出3种写法的代码示例,可以很方便的复制使用,需要的朋友可以参考下

第一种方式:

$(document).ready(function(){

$("#clickme").click(function(){

alert("Hello World click");

});

第二种方式:

?

1

2

3

$('#clickmebind').bind("click", function(){

alert("Hello World bind");

});

第三种方式:

?

1

2

3

4

$('#clickmeon').on('click', function(){

alert("Hello World on");

});

});

注意:第三种方式只适用于jquery 1.7以上的版本

源码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<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="js/jquery.metadata.js"></script>

<script type="text/javascript" src="js/messages_zh.js"></script>

<style type="text/css">

#frm label.error {

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>

<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>

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
点此处就本文及相关问题在本站进行非正式的简要咨询(便捷快速)】     【点此处查询各地各类考试咨询QQ号码及交流群
上一篇:JavaScript中使用Object.prototype.toString判断是否为数组
下一篇:浅谈类似于(function(){}).call()的js语句
易贤网手机网站地址:JQuery调用绑定click事件的3种写法
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!