JQ实时监听input的value值


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body id="lia-body">
    <div class="lia-content">
        <div class="inputwrapper">
            <label><span>姓名:</span><input type="text" name="fullname"></label>
            <div class="result"></div>
        </div>
    </div>
    <script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
        $(function(){
            var $inputwrapper = $('#lia-body .lia-content .inputwrapper');
            $inputwrapper.find('input').on('input propertychange',function(){
                var result = $(this).val();
                console.log(result);
                $inputwrapper.find('.result').html(result);
            });
        })
    </script>
</body>
</html>
1)当前对象属性改变,并且是由键盘或鼠标事件激发的(脚本触发无效)
2)当前对象失去焦点(onblur);
onpropertychange
只要当前对象属性发生改变,都会触发事件,但是它是IE专属的;
oninput是onpropertychange的非IE版本,支持firefox和opera等浏览器
但不同的是,它绑定于对象时,并非该对象所有属性改变都能触发事件,只有在对象的value值发生改变时才会生效。
这里我们用来监听input value的改变再好不过了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM