向我这么使用的很少,简介如下:
我使用MVC2 Control返回JsonResult。使用JQuery,传递完成调用一个回调函数。因此我在这个回调函数中添加CheckBox。代码如下:
//获得checkBoxList的table
var tbl = document.getElementById("ctl00_MainContent_checkBoxList1");
var lastRow = tbl.rows.length; //获得table 的行数
// insert row
var row = tbl.insertRow(lastRow);
row.name = "sat_del";
row.id = "sat_del";
var cell = row.insertCell(0);
var el = document.createElement("input");
el.type = "checkbox";
el.id = "sat_delivery";
cell.appendChild(el);
//注意:el.checked=true放到上一行的上面,不起作用。我的最开始解决方案
// //var checkBox = document.getElementById("sat_delivery");
//checkBox.checked = true;
//后来查询网上,http://www.cnblogs.com/net205/archive/2008/08/31/1280432.html说明了此问题。因此我才将此行代码下移
el.checked = true;
//var cell2 = row.insertCell(1); //此行不用,要是执行多了一列
var el2 = document.createElement("label");
el2.For = "sat_delivery";
el2.innerHTML = data[0].sname; //这里不能使用Text,Title,Value等属性。好像可以使用InnerText代替,没有测试过
cell.appendChild(el2);
最近学习MVC2,写了这么点经验请各位Web高手笑话,这是解决个小问题