JQ simulation operation

demo.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
body {
	font-size: 13px;
	line-height: 130%;
	padding: 60px;
}
p {
	width: 200px;
	background: #888;
	color: white;
	height: 16px;
}
</style>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('#btn').bind("click", function(){
		$('#test').append("<p>My binding function 1</p>");
	}).bind("click", function(){
		$('#test').append("<p>My binding function 2</p>");
	}).bind("click", function(){
		$('#test').append("<p>My binding function 3</p>");
	});
	$('#btn').trigger("click");
})
</script>
</head>
<body>
<button id="btn">Click me</button>
<div id="test"></div>
</body>
</html>

Effect picture:

 

demo2.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
body {
	font-size: 13px;
	line-height: 130%;
	padding: 60px;
}
p {
	width: 200px;
	background: #888;
	color: white;
	height: 16px;
}
</style>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('#btn').bind("myClick", function(){
		$('#test').append("<p>My custom event.</p>");
	});
	$('#btn').click(function(){
		$(this).trigger("myClick");
	}).trigger("myClick");
})
</script>
</head>
<body>
<button id="btn">Click me</button>
<div id="test"></div>
</body>
</html>

Effect picture:


demo3.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
body {
	font-size: 13px;
	line-height: 130%;
	padding: 60px;
}
p {
	width: 200px;
	background: #888;
	color: white;
	height: 16px;
}
</style>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('#btn').bind("myClick", function(event, message1, message2){
		$('#test').append( "<p>"+message1 + message2 +"</p>");
	});
	$('#btn').click(function(){
		$(this).trigger("myClick",["My Custom","Event"]);
	}).trigger("myClick",["My Custom","Event"]);
})
</script>
</head>
<body>
<button id="btn">Click me</button>
<div id="test"></div>
</body>
</html>

Effect picture:

 

demo4.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
}
body {
	font-size: 13px;
	line-height: 130%;
	padding: 60px;
}
p {
	width: 200px;
	background: #888;
	color: white;
	height: 16px;
}
</style>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('#old').bind("click", function(){
		$("input").trigger("focus");
	});
	$('#new').bind("click", function(){
		$("input").triggerHandler("focus");
	});
	$("input").focus(function(){
		$("body").append("<p>focus.</p>");
	})
})
</script>
</head>
<body>
<button id="old">trigger</button>
<button id="new">triggerHandler</button>
<input />
</body>
</html>

Effect picture:

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931914&siteId=291194637