Home  >  Article  >  Web Front-end  >  jquery adds event_html/css_WEB-ITnose to HTML elements

jquery adds event_html/css_WEB-ITnose to HTML elements

WBOY
WBOYOriginal
2016-06-24 12:06:38989browse

In a piece of html code, a8603e7d2fae5f26489c2132e246fbd0click65281c5ac262bf6d81768915a4a77ac0
How to use js or jquey to change it into cfcbadc4a2fa0d6021524f75a5cc26a9Click65281c5ac262bf6d81768915a4a77ac0


Reply to discussion (solution)

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(){});

High version can use:
$("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(){});

Use higher versions:
$("body").on("click","#bt1",function(){});



Why is it called when the event is bound instead of when the button is clicked?


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

Statement:
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