Last active
December 29, 2015 12:19
-
-
Save marsen/7670155 to your computer and use it in GitHub Desktop.
.On vs .Live in JQuery,Attach an event, now and in the future.
Using jquery-1.8.3.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> | |
<script> | |
$(function(){ | |
$('#wrapper').on('click','#onlink',function(event){ | |
alert('on link was clicked'); | |
}); | |
$("#livelink").live('click',function(){ | |
alert('live link was clicked'); | |
}); | |
$("#btn").click(function(){ | |
$("#wrapper").html("<a href='#' id='livelink' >live click</a><br /><a href='#' id='onlink' >on click</a><br /><a href='#' >other click</a><br />"); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
On vs Live in JQuery,Attach an event, now and in the future.<br /> | |
<input id="btn" type="button" value="text" /> | |
<div id="wrapper"> | |
</div> | |
</body> | |
<html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.9以後應以on取代live