Can jQuery check whether input content has changed?

前端 未结 9 1036
轮回少年
轮回少年 2020-12-23 19:30

Is it possible to bind javascript (jQuery is best) event to \"change\" form input value somehow?

I know about .change() method, but it does not trigger

9条回答
  •  借酒劲吻你
    2020-12-23 19:52

    function checkChange($this){
        var value = $this.val();      
        var sv=$this.data("stored");            
            if(value!=sv)
                $this.trigger("simpleChange");    
    }
    
    $(document).ready(function(){
        $(this).data("stored",$(this).val());   
            $("input").bind("keyup",function(e){  
            checkChange($(this));
        });        
        $("input").bind("simpleChange",function(e){
            alert("the value is chaneged");
        });        
    });
    

    here is the fiddle http://jsfiddle.net/Q9PqT/1/

提交回复
热议问题