我想在成功时更改按钮文字..我想在成功后将其更改为已接受
<button type="button" onclick="saveData<?php echo $row1->id; ?>()">Accept</button>
<script>
function saveData<?php echo $rrr->id; ?>(){
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/accept_seller/'. $rrr->id; ?>",
data:{},
success:function( data )
{
}
});
}
我的功能正常工作,因为我在成功后使用了警报,但我不知道如何在成功后使用它的文本。请帮忙
答案 0 :(得分:2)
您可以将班级与按钮相关联:
<button type="button" onclick=".." class="submit-btn">Accept</button>
现在,在您的AJAX成功代码中,请提及以下内容:
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/accept_seller/'. $rrr->id; ?>",
data:{},
success:function( data ) {
$(".submit-btn").html("Accepted"); // Add this line
}
});
答案 1 :(得分:0)
1)在函数
中传递this
2)使用.text()
功能更改按钮文本。
<button type="button" onclick="saveData<?php echo $row1->id; ?>(this)">Accept</button>
<script>
function saveData<?php echo $rrr->id; ?>(obj){
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/accept_seller/'. $rrr->id; ?>",
data:{},
success:function( data )
{
$(obj).text("New Text");
}
});
}
</script>
答案 2 :(得分:0)
HTML:在按钮中添加ID
<button type="button" id="accept" onclick="saveData<?php echo $row1->id; ?>()">Accept</button>
脚本:
success:function( data ) {
$("#accept").html("accepted");
}
答案 3 :(得分:0)
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/accept_seller/'. $rrr->id; ?>",
data: {},
success: function(data) {
$("#btn").text('your new text here'); // add id to your button
}
});
<button id="btn" type="button" onclick="saveData<?php echo $row1->id; ?>()">Accept</button>
答案 4 :(得分:0)
id; ?>()“>接受 函数saveDataid; ?>(){
$.ajax({
type: "POST",
url: "<?php echo base_url().'home/accept_seller/'. $rrr->id; ?>",
data:{},
success:function( data )
{
$("#buttonid").html('Changetext');
}
});