jquery adds event_html/css_WEB-ITnose to HTML elements

WBOY
Release: 2016-06-24 12:06:38
Original
988 people have browsed it

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


Reply to discussion (solution)

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

High version can use:
$("body").on("click","#bt1",function(){});
Copy after login
Copy after login



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

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



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


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>
Copy after login
It has been tested and can be used. Remember to import JQ

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!