jQuery值更改事件 [英] Jquery value change event

查看:91
本文介绍了jQuery值更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,当我单击按钮时它会向我显示一些消息.它在IE上很好用,但在ff或chrome上不起作用,有人告诉我为什么?对不起我的英语不好.

I have some code,when I click the button it show me some message.It works on IE good,but dont works on ff or chrome,somebody tell why?Sorry for my poor english.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title> New Document </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
        $(function(){
            $("#test").bind("input propertychange",function(){
                alert("abc");
            });
        });
        function ff() 
                { 
                document.getElementById('test').value=Math.random(); 

    </script>
</head>
<body>
    <input id="test"></input>
    <input id='btn' value="tt" type="button" onclick="ff()" /> 
</body>
</html>

推荐答案

代码中有一些错误:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title> New Document </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
    $(function () {
        $('#btn').on('click', function () {
            $('#test').val(Math.random());
            $('#test').trigger('change');
        }); //missing ending }
        $('#test').bind("change paste keyup", function () { // change to a proper listener 
            alert("abc");
        });
    });
    </script>
</head>
<body>
    <input id="test" type="text" value="" />
    <!--             ^ Specify a "type" -->    
    <input id='btn' value="tt" type="button" /> 
</body>
</html>

这篇关于jQuery值更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆