keyup事件不适用于easyui

时间:2016-05-01 04:48:26

标签: javascript jquery jquery-easyui

我的easyui文本框有问题。我有这个HTML

<input name="telefone" id="telefone" class="f1 easyui-textbox" data-options="required:true" />

这个js代码:

$('#telefone').textbox({
            onChange:function(v){
                    var r = v.replace(/\D/g,"");
                    r = r.replace(/^0/,"");
                    if (r.length > 11) {
                        // 11+ digits. Format as 5+4.
                        r = r.replace(/^(\d\d)(\d)(\d{4})(\d{4}).*/,"($1)$2.$3-$4");
                    }
                    else if (r.length > 6) {
                        // 6..10 digits. Format as 4+4
                        r = r.replace(/^(\d\d)(\d)(\d{0,4})(\d{0,4}).*/,"($1)$2.$3-$4");
                    }
                    else if (r.length >= 3) {
                        // 3..5 digits. Add (0XX..)
                        r = r.replace(/^(\d\d)(\d)(\d{0,5})/,"($1)$2.$3");
                    }
                    else {
                        // 0..2 digits. Just add (0XX
                        r = r.replace(/^(\d*)/, "($1");
                    }

                    if (r != v) {
                        $('#telefone').textbox('setText',r);
                    }
                }
        });

这个工作非常好但是onChange就像onblur一样工作我希望它像onkeyup一样工作。所以我尝试了这个:

 $("#telefone").keyup(function() {
            alert("ok");
 });

没有成功= /

感谢您的关注。

1 个答案:

答案 0 :(得分:0)

试试这个。它绝对有用。

s