需求说明 根据状态 判断显示隐藏 我要做的是进来根据状态判断这个单子是否支付了 支付过 按钮隐藏的一个小demo
错误的例子
function searchLIst(e) {
let str1 = ""
$.ajax({
url:"wx/order/"+e,
type:"get",
data:{
},
dataType: 'json',
success:function(data){
if(data.type==1){
data.type="代客祭扫"
}else if(data.type==2){
data.type="元宵送灯"
}else if(data.type==3){
data.type="鲜花租摆"
}
if(data.status==0){
data.status = "待支付"
}else if(data.status==1){
data.status = "已支付"
}else if(data.status==2){
data.status = "已接受"
}
if(data.responseJSON.status=="已接受"||data.responseJSON.status=="已支付"){
$("#submit").hide()
}
//将拿到的值显示到jsp页面
str1 += `
<div class="from">
<div class="public">
<div class="public-left">下单时间:</div>
<div class="public-right">${data.serviceDate} </div>
</div>
<div class="public">
<div class="public-left">订单类型:</div>
<div class="public-right">${data.type}</div>
</div>
<div class="public">
<div class="public-left">订单内容:</div>
<div class="public-right">${data.tombArea}-${data.rankNo}号-${data.name} </div>
</div>
<div class="public">
<div class="public-left">特殊要求:</div>
<div class="public-right">${data.remarks}</div>
</div>
<div class="top-border">
<div class="public">
<div class="public-left">联系客服:</div>
<div class="public-right">400-444-4444 </div>
</div>
<div class="public">
<div class="public-left">订单状态:</div>
<div class="public-right">${data.status }</div>
</div>
<div class="public">
<div class="public-left">费用金额:</div>
<div class="public-right">${data.amount}元 </div>
</div>
</div>
</div>
<div class="submit">
<input type="button" value="支 付" onclick="pay(${data.id})" id="submit">
</div>
`;
$(".wrap").html(str1)
},
error:function(e){
// alert("错误!!");
}
});
}
说下这个错误的原因 以为你的html还没加载完毕 你来获取id元素是获取不到的 所以按钮不会隐藏的
正确实例
function searchLIst(e) {
let str1 = ""
$.ajax({
url:"wx/order/"+e,
type:"get",
data:{
},
dataType: 'json',
success:function(data){
if(data.type==1){
data.type="代客祭扫"
}else if(data.type==2){
data.type="元宵送灯"
}else if(data.type==3){
data.type="鲜花租摆"
}
if(data.status==0){
data.status = "待支付"
}else if(data.status==1){
data.status = "已支付"
}else if(data.status==2){
data.status = "已接受"
}
//将拿到的值显示到jsp页面
str1 += `
<div class="from">
<div class="public">
<div class="public-left">下单时间:</div>
<div class="public-right">${data.serviceDate} </div>
</div>
<div class="public">
<div class="public-left">订单类型:</div>
<div class="public-right">${data.type}</div>
</div>
<div class="public">
<div class="public-left">订单内容:</div>
<div class="public-right">${data.tombArea}-${data.rankNo}号-${data.name} </div>
</div>
<div class="public">
<div class="public-left">特殊要求:</div>
<div class="public-right">${data.remarks}</div>
</div>
<div class="top-border">
<div class="public">
<div class="public-left">联系客服:</div>
<div class="public-right">400-444-4444 </div>
</div>
<div class="public">
<div class="public-left">订单状态:</div>
<div class="public-right">${data.status }</div>
</div>
<div class="public">
<div class="public-left">费用金额:</div>
<div class="public-right">${data.amount}元 </div>
</div>
</div>
</div>
<div class="submit">
<input type="button" value="支 付" onclick="pay(${data.id})" id="submit">
</div>
`;
$(".wrap").html(str1)
},
error:function(e){
// alert("错误!!");
},
complete:function (data) {
if(data.responseJSON.status=="已接受"||data.responseJSON.status=="已支付"){
$("#submit").hide()
}
}
});
}
complete这个函数是在所有都执行完成后在来执行他 所以我们的正好可以用到 在我执行完所有的thml还要判断之后 在complete里来取id元素 和判断 这样就成功了