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.