c if 判断状态 、控制div 动态展示图片按钮

// 启用、停用按钮样式

    $(".switch").each(function () {
        $(this).click(function () {
            $(this).find("div:eq(1)").toggle()
            $(this).find("div:eq(0)").toggle()
        })
    })

//div 引用此样式、div 加点击事件,c 标签根据数据库查询的参数,判断状态展现不同的按钮

<div class="switch" id="switchdiv" name="switchdiv" onclick="editorstate('${row.guide_ID}','${row.enable}')">

<c:if test="${row.enable == true}">
<div>
<img src="<%=path%>/common/images/disabled.png">停用
</div>
</c:if>
<c:if test="${row.enable == false}">
<div>
<img src="<%=path%>/common/images/abled.png">启用
</div>
</c:if>
</div>


// js 代码 

点击启用或停用(同一按钮),这里 用 toastr 插件做提醒框

function editorstate(obj, obj2) {
$.ajax({
data : {
Enable :obj2,
Guide_ID :obj,
},
url : "updateguidisplay",
/* 
拼接字符串传参 : 
url : "uploadSlid.html?Url=" + $("#test0").val() + "&businessname=" + $("#test1").val() + "&titles=" + $("#test1").val(),*/ 
type : "post",
dataType : "json",
async : false,
contentType : "application/x-www-form-urlencoded; charset=utf-8",
success : function(data) { 
debugger;
if (data.result == "success") {
toastr.success("状态已修改");
setTimeout(function() {
window.location.reload();
},1000);

}
if (data.result == "error") {
toastr.success("已停用");
setTimeout(function() {
window.location.reload();
},1000);
}
}
});
}

猜你喜欢

转载自blog.csdn.net/qq_26289533/article/details/78549483