jquery文本改变事件绑定

 focus:获得焦点时触发事件

             keyup:按键弹起时触发事件

             keypress:按键按下时触发事件(先响应事件,再显示输入结果(获得的是上一次结果),可能被输入法拦截)

             propertychange:属性改变时触发事件(不管是获得焦点还是value改变等)

 

<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);
    });
    -->
posted @ 2012-07-06 13:13  寂静之秋  阅读(657)  评论(0编辑  收藏  举报
哈尔滨八零网