jquery绑定元素id事件_JQuery绑定click事件的3种写法

1.首先你得有jquery 1.7以上的版本的js

2.将js导入项目

e11909e8f87552ae45a561cb8e7e452d.png

3.jsp源码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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.效果图:其他的就不一一测试了

e84d296ba6c2c0eda6efe0fca1776167.png

相信很多人在刚接触前端或者中期时候总会遇到一些问题及瓶颈期,如学了一段时间没有方向感或者坚持不下去一个人学习枯燥乏味有问题也不知道怎么解决,对此我整理了一些资料 喜欢我的文章想与更多资深大牛一起讨论和学习的话 欢迎加入我的学习交流群

→点这里​jq.qq.com

版权声明:本文为weixin_35998457原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。