//一定要写在table下,否则会出现d.id取不到值得问题
<script type="text/html" id="switchTpl">
<!--这里的 checked 的状态只是演示-->
<input type="checkbox" name="open" value="{{d.isstop}}" lay-skin="switch" lay-text="启用|关闭" lay-filter="sexDemo" {{ d.isstop==1 ? 'checked' : '' }} data-id="{{d.id}}">
</script>
form.on('switch(sexDemo)', function(obj) {
//console.log(obj);
var id = obj.elem.attributes["data-id"].value;
console.log(id);
if(obj.elem.checked == true) {
this.value = 1;
} else {
this.value = 0;
}
layer.tips(this.value + ' ' + this.name + ':' + obj.elem.checked, obj.othis);
$.post('http://192.168.1.136:10086/role/isstop', {
id: id,
isstop: this.value
}, function(data, status) {
console.log(data);
if(data.status == 1) {
layer.msg(data.msg);
} else {
layer.msg(data.msg);
}
})
});