easyui部分组件使用经验
easyui-switchbutton
需要实现在数据表格中有一列如下图,最开始参考官网,不完全可用,还得借助百度:
//其中onclick都是不可行的,是错误示例
{
title: '状态',field: 'ie',align: "center",width: 100,
formatter: function (value, row, index) {
if (value === 'Y') {
return "<form><input id='" + row.id + "' class='easyui-switchbutton switchBtn' data-options=\"onText:'启用',offText:'禁用' \" checked onclick=changeState1(" + JSON.stringify(row).replace(/"/g, '"') + ")></form>"
} else if (value === 'N') { return "<form><input id='" + row.id + "' class=\"easyui-switchbutton switchBtn\" data-options=\"onText:'启用',offText:'禁用', onclick: changeState1(" + JSON.stringify(row).replace(/"/g, '"') + ") \"></form>"
}
}
}, `
//简单的正确示例
return "<form><input id='" + row.id + "' class='easyui-switchbutton switchBtn'></form>"
//正确示范
onLoadSuccess: function (data) {
$('.editParam').linkbutton();
$(".switchBtn").switchbutton({
height: 18,
onText: "启用",
offText: "停用",
onChange: function (checked) {
//Y启用 true N禁用 false
var state = 'Y';
if (!checked) {
state = 'N';
}
var id = $(this).attr("id");
//错误示范
// $('#sw111').switchbutton({
// onChange: function(data){
// console.log("datasw111:" +JSON.stringify(data))
// }});
// $('.switchBtn').switchbutton({
// onChange: function(data){
// console.log("datasw:" +JSON.stringify(data))
// }
// })
1.class=‘easyui-switchbutton switchBtn’ 并且配合 ( " . s w i t c h B t n " ) . s w i t c h b u t t o n ( ) 才 能 显 示 成 功 2. 点 击 该 按 钮 调 用 启 用 禁 用 方 法 , 在 单 行 o n c l i c k 调 用 外 部 方 法 不 行 , 使 用 (".switchBtn").switchbutton()才能显示成功 2.点击该按钮调用启用禁用方法,在单行onclick调用外部方法不行,使用 (".switchBtn").switchb