Home > Web Front-end > JS Tutorial > Why can't jquery click event with specified ID be triggered?

Why can't jquery click event with specified ID be triggered?

黄舟
Release: 2017-06-27 10:18:49
Original
2405 people have browsed it

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>
Copy after login

This is the button<button id="b01" type="button">Change Content</button>

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 <button id="b01" type="button">Change Content</button>
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>
Copy after login
<button id="b01" type="button">Change Content</button>
Copy after login

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 include>, 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template