javascript - Recently, when processing business logic, I unbind the same element first and then bind again, and found a usage problem.
某草草
某草草 2017-06-26 10:58:53
0
2
930

After unbinding first, bind sometimes fails. Some business requirements no longer need to be bound, and some need to be re-bound.
The following is a simple example

window.onload=function(){
   $("input").unbind();
}            
$("input").bind("click",function(){
   alert("1");
})

This cannot be rebinded

Written like this, you can bind

        $("input").unbind();
        $("input").bind("click",function(){
            alert("1");
        })

Ask the reason for this problem? Expert analysis

某草草
某草草

reply all(2)
洪涛

The execution order is different. The unbind in onload is executed after the bind below, so you bind first, then unbind after onload

伊谢尔伦

You bound a click event to the input, but the click event was removed from your window.onload

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template