【发布时间】:2018-02-07 14:38:42
【问题描述】:
我有两个按钮“插入”和“选择”,它们用于使用 AJAX 插入和显示记录,我希望它们都应该具有独立的功能,例如,每当我单击选择按钮时,应该显示记录当我单击插入时,应该插入记录。现在在下面的代码中,选择的第二个按钮取决于单击插入按钮。然后我想独立工作。
<script>
$(document).ready(function(){
$('#insert').click(function(event){
event.preventDefault();
$.ajax({
url:"back1.php",
method:"post",
data:$('form').serialize(),
dataType:"html",
success:function(strMsg)
{
$('#select').click(function(event){
event.preventDefault();
$.ajax({
url:"back1.php",
dataType:"html",
success:function(strMsg)
{
$('#Smsg').html(strMsg);
}
});
});
$('#Imsg').html(strMsg);
}
});
});
});
</script>
【问题讨论】:
-
它们是依赖的,因为你在插入按钮的成功函数中定义了选择按钮的方法。
-
@axel.michel 我可以想出同样的方法,但不知道如何让它们独立。请帮忙。