In a piece of html code,
How to use js or jquey to change it into
Add an ID to the button
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
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
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
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
< button type="button" id="bt1">click
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>