a-link正在index.php中工作。但是如果a-link来自ajax响应,则A-link无法正常工作,我想通过响应a-link调用相同的函数。这是我的完整代码。请用完整的代码解释。
的index.php
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function(){
function SelRej(){
var SRvalue = $(this).attr("value");
//alert(SRvalue);
var URL = "Ajax.php";
$("#"+SRvalue).load(URL, {
"SRvalue":SRvalue
});
if(SRvalue=="Reject"){$("#Select").html("<a href='#' class='Select' value='Select'>Select</a>");}
if(SRvalue=="Select"){$("#Reject").html("<a href='#' class='Reject' value='Reject'>Reject</a>");}
return false;
}
$(".Select").on('click', SelRej);
$(".Reject").on('click', SelRej);
});
</script>
</head>
<body>
<div id="Select"><a href='#' class='Select' value="Select">Select</a></div>
<div id="Reject"><a href='#' class='Reject' value="Reject">Reject</a></div>
</body>
</html>
Ajax.php
<?php
if( $_REQUEST["SRvalue"] ){
$SRvalue = $_REQUEST['SRvalue'];
if($SRvalue=="Select"){echo "Selected";}
if($SRvalue=="Reject"){echo "Rejected";}
}
?>
答案 0 :(得分:0)
我正在寻找
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function(){
function SelRej(){
var SRvalue = $(this).attr("value");//alert(SRvalue);
$.ajax({
url: "Ajax1.php",
cache: false,
method: "GET",
data: {SRvalue: SRvalue}
}).done(function(response) {
var splitted = response.split("|");
$("#Select").html(splitted[0]); //alert(splitted[0]);
$("#Reject").html(splitted[1]); //alert(splitted[1]);
});
}
//$(".Select").on('click', SelRej);
//$(".Reject").on('click', SelRej);
$("body").on('click', ".Select", SelRej);
$("body").on('click', ".Reject", SelRej);
});
</script>
</`head`>
<body>
<div id="Select"><a href='#' class='Select' value="Select">Select</a></div>
<div id="Reject"><a href='#' class='Reject' value="Reject">Reject</a></div>
</body>
</html>
Ajax1.php
<?php
if( $_REQUEST["SRvalue"] ){
$SRvalue = $_REQUEST['SRvalue'];
if($SRvalue=="Select")
{
echo "Selected|<a href='#' class='Reject' value='Reject'>Reject</a>";
}
else if($SRvalue=="Reject")
{
echo "<a href='#' class='Select' value='Select'>Select</a>|Rejected";
}
}
?>