动态创建的DOM元素进行事件绑定

http://files.cnblogs.com/files/xsmhero/jquery.livequery.js

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'></script> <script type="text/javascript" src="jquery.livequery.js"></script>

<input type="button" id="create" value="点击这里" />
<div id="msg"></div> <script type="text/javascript">
function checkName(id){
  alert('验证NAME');
} $(
function(){ $("#create").click(function(){ var vv ="<input type=\"text\" id="name" name=\"name\" onblur=\"checkName('name')\" />"); $("#msg").html(v);
}); $("#name").livequery('blur',function(){
alert('绑定了单击事件');
    checkName($(this).attr("id"));
}); }); </script>

 

<input type="button" id="create" value="点击这里" /> 

你可能感兴趣的:(dom)