js触发button的点击事件

1. $(".tab").click(function () {  })

2. $(".tab").on("click",function () {  })

3. $(document).on("click", ".tab",function () {  })

4. 使用<onclick="">触发函数

 

function load(){
    //下面两种方法效果是一样的
    document.getElementById("target").onclick();
    document.getElementById("target").click();
}
$(function(){
                
  // test 的点击事件
  $("#test").click(function(){
                
    alert("点击了");
  });
                
  // 调用 test 的点击事件的两种方法
   $("#test").trigger("click");
   $("#test").click()
})

JQuery绑定click事件的3种写法: 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
 
<script type="text/javascript" src="../js/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="../css/WdatePicker.css"> 
<script type="text/javascript">
$(document).ready(function(){
	$("#text").bind("click",function(){
		alert("我的id为text,你点击时触发");
	});
	
	$("#text1").on("click",function(){
		alert("hellworl");
	});
	
	$("#text2").click(function(){
		alert($("#text2").val());
		
	});
});
	
	
</script>
<body>
	
	<input id="text" type="button" value="点击"/> 
	
	<input id="text1" type="button" value="点击"/> 
	
	<input id="text2" type="text" value="love"/> 
</body>
</html>

 

  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值