Home > Article > Web Front-end > Why can't jquery click event with specified ID be triggered?
I just encountered this problem using jquery, click did not respond.
jquery is like this
<script type="text/javascript"> $(document).ready(function(){ alert("1"); $("#b01").click(function(){ alert("2"); }); }); </script>
This is the button6fb7865d740640142e12b72a0cb779f2Change Content65281c5ac262bf6d81768915a4a77ac0
When the page is refreshed, the box 1 will pop up, but the box for clicking button 2 not only pops up, but there is no response. Why? !
There is no problem with this part of the code under FF. It is estimated that 6fb7865d740640142e12b72a0cb779f2Change Content65281c5ac262bf6d81768915a4a77ac0
You will follow this part Generated, this part has not been loaded when $(document).ready.
Tested to be normal
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ alert("1"); $("#b01").click(function(){ alert("2"); }); }); </script> 这个是按钮<button id="b01" type="button">Change Content</button> </body> </html>
<button id="b01" type="button">Change Content</button>
is written directly in the body, so it is not loaded?
If it is a problem of not loading, is there any way to solve it?
If you write it directly in html, you can check whether there are spelling errors or something. Independent tests such as 2# can be run.
No problem, FF, IE and Google have all tried it. Are you sure you pressed Change Content and not "Send"?
It won’t work if it contains 3ecb10d239616da4e9c4acbd558c0643, just delete it. Why?
Then it may be that your include part also has an element id called b01. If I remember correctly, the ID selector will only return the first element.
There seems to be some conflict? Just change $ to jQuery, thank you everyone
The above is the detailed content of Why can't jquery click event with specified ID be triggered?. For more information, please follow other related articles on the PHP Chinese website!