Home > Article > Web Front-end > jquery adds event_html/css_WEB-ITnose to HTML elements
In a piece of html code, a8603e7d2fae5f26489c2132e246fbd0click65281c5ac262bf6d81768915a4a77ac0
How to use js or jquey to change it into cfcbadc4a2fa0d6021524f75a5cc26a9Click65281c5ac262bf6d81768915a4a77ac0
Add an ID to the button
a502af8753acd935203771b147f5f8abClick65281c5ac262bf6d81768915a4a77ac0
Js--JQ:
$("#bt1").attr("onclick",function (){
alert("111");
})
About this
As long as you can find this element, the event is still easy to add
$('button').click(function(){
});
Add an ID to the button
7aca22a161b0577fe7c5aa9201a0e0a6Click65281c5ac262bf6d81768915a4a77ac0
Js--JQ:
$("#bt1").attr("onclick",function(){
alert("111");
})
About like this
Using this method, why does alert execute when I append this html code segment, but the "click" button after appending does not execute
Add an ID to the button
a502af8753acd935203771b147f5f8abClick65281c5ac262bf6d81768915a4a77ac0
Js--JQ:
$("#bt1").attr("onclick",function(){
alert("111");
})
About like this
Use this Method, why does alert execute when I append this html code segment, but the "click" button after appending does not execute?
Then you can check which version of jq you are using. Please read the documentation for details
Low version can use
$("#bt1").live("click",function(){});
$("body").on("click","#bt1",function(){});
Add an ID to the button
1e6022b18e33c8b74fbe5a9006885e3cClick65281c5ac262bf6d81768915a4a77ac0
Js--JQ:
$("#bt1").attr("onclick",function(){
alert("111");
})
Probably like this
Using this method, why does alert execute when I append this html code segment, but after appending " Clicking the " button will not execute
Then you can check which version of jq you are using. Please read the documentation for details
You can use lower versions
$("#bt1").live("click",function(){});
$("body").on("click","#bt1",function(){});
Add an ID to the button
3bed42c15c06c5f7da56633e405c6ca0click65281c5ac262bf6d81768915a4a77ac0
Js--JQ:
$("#bt1").attr("onclick",function() {
alert("111");
})
Probably like this
Using this method, why does alert execute when I append this html code segment, and append The "Click" button after that will not be executed
<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><script type="text/javascript" src="jquery-1.js"></script><script type="text/javascript"> var sa = $("#bt1"); function ale(){ //alert(sa) document.getElementById('bt1').setAttribute('onclick','gogogo()') } function gogogo(){ alert("ou yeah"); }</script><body><input type="button" id="bt1" value="123"/><input type="button" id="bt2" value="123312" onclick="ale()" /></body></html>It has been tested and can be used. Remember to import JQ