我有数据表设置以及引导选择,一个将复选框变成开/关开关的插件。当切换开关时,我试图获取作为 ID 的输入的名称。
这是我的代码和实时jsfiddle,当我单击开关时,警报未定义。如何让输入名称(123)发出警报?更多关于 boostrap 插件的信息在这里http://www.bootstrap-switch.org/
谢谢
testdata = [{
"id": "<input name\"123\" id=\"create-switch\" type=\"checkbox\">",
"country_code": "UK",
"title": "Legal Director",
"pubdate": "2012-03-08 00:00:00",
"url": "http://..."
}, {
"id": "59",
"country_code": "UK",
"title": "Solutions Architect,",
"pubdate": "2012-02-23 00:00:00",
"url": "http://..."
}];
$('#test').dataTable({
"aaData": testdata,
"aoColumns": [{
"mDataProp": "id"
}, {
"mDataProp": "country_code"
}, {
"mDataProp": "title"
}, {
"mDataProp": "pubdate"
}, {
"mDataProp": "url"
}],
"fnCreatedRow": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$('#create-switch', nRow).wrap('<div class="make-switch switch-mini" />').parent().bootstrapSwitch();
},
"fnInitComplete": function () {
alert("init");
$('.make-switch').on('switch-change', function (e) {
var postid = $('.make-switch input').attr('name');
alert(postid);
});
}
});