Small partners in the front page, is not often encountered with JavaScript dynamically created button buttons or other tags can not use the Click event problem. The following code, using jquery in the body to create a dynamic class for the button button, when clicked on this button can not trigger the Click event.
<script>
$ (function () {
$ ("body"). HTML ("<button class= ' demo ' > button </button>");
$ (". Demo"). Click (function () {
alert ("Bounce Window");
});
</script>
<body>
</body>
Here's a solution to jquery:
The $ (". Demo") in the above code. Click (function () {...}); Modify to $ (document). On ("click", ". Demo", function () {...});
The modified code is:
<script>
$ (function () {
$ ("body"). HTML ("<button class= ' demo ' > button </button>");
$ (document). On ("click", ". Demo", function () {
alert ("Bounce Window");
});
</script>
<body>
</body>
* * Note: There is a way online that
will be $ (". Demo"). Click (function () {...}), and modify to $ (". Demo"). On ("click", Function () {...});
But I tried it myself in this way without success. Maybe I have some local operational problems. If you test it in this way, use it as a priority. I personally feel that in the case of the use of this way is still simpler than my way.
If you have any questions that you don't understand, you can contact me by QQ.
If there are any bad writing, you are welcome to point out. Thank you. **