For jquery problems, click the button to event

Source: Internet
Author: User
For jquery, there are multiple "modify" buttons on page A of the button clicking event A and page B. Each button has A style. click ajax to page B, and the following code $ (. editbtn ). click (function () {var & nbsp; urlb. php; var & nbsp; params & nbsp; $ (form ). about jquery in seriali, click the event button
There are two pages, A and B.
There are multiple "modify" buttons on page A. Each button has A style class = "editbtn". click ajax to go to page B. The following code is displayed:
$(".editbtn").click(function(){
var url="b.php";
var params = $('form').serialize();
$.ajax({
url: url,
type: 'post',
dataType:'json',
data: params,
success: function (data){
$("#p1").html(data.html);
$("#p2").html(data.script);
}
});
});

Page B
$data=array(
'html'=>$html,
'script'=>$script
);
echo json_encode($data);

Page B also returns N "modify" buttons containing class = "editbtn", and the returned buttons cannot be completed by clicking $ (". editbtn "). click. why?
The reason why page B has 'script' => $ script is that it cannot be completed $ (". editbtn "). click event, I added the jquery above on page B, and got it $ ("# p2" ).html, so that it can run, but I feel inefficient, it seems that the same code is repeated many times after you click it many times. do you think this is good? Shouldn't it be okay?
------ Solution ----------------------
Put $ (". editbtn"). click (function (){
Change to $ (document). on ('click', ". editbtn", function (){
You can.

------ Solution ----------------------
Bind event
$ ('. Clickme'). live ('click', function (){
Alert ("Live handler called .");
});
Live: attaches an event handler function to all matching elements, even if the element is added later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.