linkForBC
是复选框ID,如果单击此复选框,我想创建新表ID option_list。
这是我的html设计。
<tr class="checkList">
<td class="bcid">BC</td>
<td>
<table id="option_list" border="0" style="width:100%;" cellspacing="0">
<tbody id="tbodyid">
</tbody>
</table>
</td>
<td></td>
如果点击它转到$('#linkForBC')这个方法。
function getDropDown(itemsSelected) {
if ($('#linkForBC').attr("checked")) {
Enterprisegateway.Models.Constants.findOver({}, function (result) {
for (var i in result)
methodName = i;
var res = IsValidSession(result[methodName]);
if (res === false || res === "false") {
$.hideprogress();
}
var json = $.parseJSON(result[methodName]);
if (json === null || json === undefined || json === '') {
$.hideprogress();
}
var result = json.Result;
var data = json.Data;
if (result === 0) {
plantTypes = data;
}
showEquipments(data, itemsSelected);
});
}
else {
//$(".checkList tr").style.display = "none";
$(".bcid").style.display = "none";
$("#tbodyid").empty();
}
}
如果我点击,我想创建表格,如果我取消选中表格,它应该销毁表格然后如果我检查,我想再创建表格。
$('#linkForBC').live("click", function () {
var itemsSelected = '';
getDropDown(itemsSelected);
});
这个创建表的方法。
function showEquipments(data, itemsSelected) {
if (data == undefined) {
return false;
}
var newLi = "<tr>";
newLi += "<td style=text-align:left;padding-left:5px;width:70%;>";
newLi += "<select id= test0 " + " name='access' lang = " + "'" + "OPTIONS" + "'" + " class='types' multiple='multiple' width='100%;' ";
for (var k = 0; k < data.length; k++) {
if (itemsSelected !== null && itemsSelected !== "" && itemsSelected.indexOf(data[k].Id) > -1) {
var selected = "selected";
newLi += " <option id=" + data[k].Id + " class='EquipmentOptions' value=" + data[k].Id + " " + selected + " >" + data[k].Name + " </option>";
}
else {
newLi += " <option id=" + data[k].Id + " class='EquipmentOptions' value=" + data[k].Id + " >" + data[k].Name + "</option>";
}
}
newLi += "</select>";
newLi += "</td>";
newLi += "</tr>";
$('#option_list').append(newLi);
$("#test0").dropdownchecklist({
onComplete: function (selector) {
values = '';
itemsToAdds = [];
for (i = 0; i < selector.options.length; i++) {
if (selector.options[i].selected && (selector.options[i].id != "")) {
if (values != "")
values += ";";
values += selector.options[i].id;
itemsToAdds.push(selector.options[i].id)
}
if (values) {
}
}
}
});
答案 0 :(得分:0)
使用on
代替live
$(function(){
$('document').on('click','#linkForBC',function(){
var itemsSelected = '';
getDropDown(itemsSelected);
})
})
GetDROPDOWN
function getDropDown(itemsSelected) {
if ($('#linkForBC:checked').val()) {
Enterprisegateway.Models.Constants.findOver({}, function (result) {
for (var i in result)
methodName = i;
var res = IsValidSession(result[methodName]);
if (res === false || res === "false") {
$.hideprogress();
}
var json = $.parseJSON(result[methodName]);
if (json === null || json === undefined || json === '') {
$.hideprogress();
}
var result = json.Result;
var data = json.Data;
if (result === 0) {
plantTypes = data;
}
showEquipments(data, itemsSelected);
});
}
else {
//$(".checkList tr").style.display = "none";
$(".bcid").style.display = "none";
$("#tbodyid").empty();
}
}
ShowEquipment
function showEquipments(data, itemsSelected) {
// Create table and append
}