我想在提交表单后更改文本。我希望当我点击提交给 friend 1
时,文本更改为邀请给您的 friend
,但不更改提交给 friend 2
。当我点击提交给 friend 2
时,然后更改提交给 friend 2
的文本。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".flip").click(function(){
$(this).next().find(".panel").slideToggle("slow");
});
});
function send_to_friend(){
$.ajax({
type:"post",
url:"mail.php",
data:dataString,
cache:false,
success: function(data){
$('.panel').slideUp("slow");
$('.flip').html("Invited to Your friend");
}
});
return false;
}
</script>
我的表格在这里..
<style>
.flip{
cursor:pointer;
font-family: "Open Sans", Arial, sans-serif;
color: #2ea3f2;
text-decoration:underline;
font-size: 14px;
}
.panel{
margin:5px 0;
padding:21px;
display:none;
background-color: #f6f6f6;
border: solid 1px #c3c3c3;
}
.submitfield_style{
width: 87px;
height: 29px;
border: 1px solid #ccc;
background: #fff;
color: #999;
cursor: pointer;
}
</style>
<h5 class="flip">Send to a friend 1<h5>
<div class="panel">
<form method="post" action="">
<input type="submit" name="submit" id="submit" class="submitfield_style" onClick="return send_to_friend()">
</form>
</div>
<h5 class="flip">Send to a friend 2<h5>
<div class="panel">
<form method="post" action="">
<input type="submit" name="submit" id="submit" class="submitfield_style" onClick="return send_to_friend()">
</form>
</div>
最佳答案
您对 <h>
使用相同的类标识符元素。它将更改两者的文本。您需要使用将在 Ajax 代码中使用的不同标识符来更改文本。
关于javascript - ajax成功后如何更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381049/