Where the jquery code is placed will be executed?

79 3

There's a bit of doubt about the new jquery. As follows:
I add a code to a binding event in a 1, js file

$("input.num").keyup(function(){ 
 var tmptxt=$(this).val(); 
 $(this).val(tmptxt.replace(/D|^0/g,'')); 
}).bind("paste",function(){ 
 var tmptxt=$(this).val(); 
 $(this).val(tmptxt.replace(/D|^0/g,'')); 
})

Then, when the page references this 1. Js, it's found that the event binding isn't successful. Then I put this code in the ready function of this page of jquery, found that it could be used because the java script was executed in order, and I was

<script></script>

It works, but it doesn't look like this.
2 Answers

122 1

If not, you probably put the js code on the head of the html. If you say that the java script is executed in order, the jquery selector is unable to get this element if you put the js in the html of the input, because the

So it's the most safe to put the code in document is ready event. Because all the dom documents have been loaded.

55 5

If not, you probably put the js code on the head of the html. If you say that the java script is executed in order, the jquery selector is unable to get this element if you put the js in the html of the input, because the

So it's the most safe to put the code in document is ready event. Because all the dom documents have been loaded.

132 4

Any jquery code is placed in $ ( document ), ready ( ), and $ ( document ), ready ( ), and so on.
look at http://www.chengxuyuans.com/jquery/do....

145 3

Any jquery code is placed in $ ( document ), ready ( ), and $ ( document ), ready ( ), and so on.
look at http://www.chengxuyuans.com/jquery/do....

...