介绍:change:焦点离开时触发事件
focus:获得焦点时触发事件
keyup:按键弹起时触发事件
keypress:按键按下时触发事件(先响应事件,再显示输入结果(获得的是上一次结果),可能被输入法拦截)
propertychange:属性改变时触发事件(不管是获得焦点还是value改变等)
code:
<html>
<head>
<title>Jquery操作DOM对象</title>
<script type="text/javascript" src="D:/jquery study/jquery_js/jquery-1.6.4.js"></script>
<script type="text/javascript">
$(function(){
$(".txt").bind("propertychange",function(){
var txtChange = $("input").val();
$("#p2").html(txtChange);
});
})
</script>
</head>
<body>
<input type="text" name="test" class="txt" value="test"/>
<p id="p2"></p>
</body>
</html>
绑定事件:
<!--
$(".txt").change(function(){
$(".txt").val("");
});
$(".txt").focus(function(){
$(".txt").val("");
});
$(".txt").keyup(function(){
var txtChange = $("input").val();
$("#p2").html(txtChange);
});
$(".txt").keypress(function(){
var txtChange = $("input").val();
$("#p2").html(txtChange);
});
$(".txt").bind("propertychange",function(){
var txtChange = $("input").val();
$("#p2").html(txtChange);
});
-->