gpt4 book ai didi

javascript - 是否可以在脚本中的 php echo 中显示和隐藏按钮?

转载 作者:行者123 更新时间:2023-11-30 14:01:28 24 4
gpt4 key购买 nike

我的问题是,当数据值更改为 Delivered 时,我无法显示或隐藏按钮。

这是我的php代码

<?php 
$cardstatus = $row['cardStatus'];
if($cardstatus == NULL){
echo '<span class="badge badge-pill badge-warning">Card Pending</span>';
} elseif($cardstatus == 'Delivered') {
echo '<span class="badge badge-pill badge-success">Delivered</span>';
//Display Done Button
echo '<script>document.getElementById("done").style.display = "block";</script>';
//Undisplay Close Button
echo '<script>document.getElementById("cancel").style.display = "none";</script>';

} else {
echo '<span class="badge badge-pill badge-info">In Process</span>';
}


?>

下面是我的按钮

//Button Cancel
<button class="btn btn-warning btn-sm cancel" data-id="<?php echo $row['id'] ?>" data-user="<?php echo $row['user'] ?>" id="cancel">Cancel</button>

//Button Done
<button class="btn btn-success btn-sm done" style="display: none;" id="done">Done</button>

我的 Ajax

    action: function () {
$.ajax({
type: "POST",
url: "accept.php",
data: {
addInfo: addInfo,
passInfo: passInfo,
id:id
},
dataType: "text",
success: function (data) {
// window.location.replace("purchased-top-up-cards.php");
$('#done').show(); //This will show but will be gone after refresh
$('#close').hide(); //This will hide but will show after refresh

},
error: function (err) {
console.log(err);

}
});
}

最佳答案

信息太少。我希望您有一个可以执行以下操作的 php:

<?php 
$cardstatus = $row['cardStatus'];
if($cardstatus == NULL){
echo '{ "type":"warning" , "text":"Card Pending" }';
} elseif($cardstatus == 'Delivered') {
echo '{ "type":"success" , "text":"Delivered" }';
} else {
echo '{ "type":"info" , "text":"In Process" }';
}
?>

在客户端

$(function() {
$("#someForm").on("submit",function(e) {
e.preventDefault(); // cancel form
$.post("accept.php",{ "addInfo": addInfo, "passInfo":"passInfo","id":id },function(res) {
$("#someContainer").append('<span class="badge badge-pill badge-'+res.status+'>'+res.text+'</span>');
$("#done").toggle(res.status=="success");
$("#cancel").toggle(res.status!="success");
});
});
});

关于javascript - 是否可以在脚本中的 php echo 中显示和隐藏按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56233241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com