方法代码
function CreateRowCopy(rowNumber) {
var strTD, strRowNumber;
strTD = "<td class='TDNormal' style='text-align:center'>";
strRowNumber = "";
if (rowNumber != null) {
strRowNumber = rowNumber.toString()
}
var strTemp = "<tr class=''>" + strTD + "<input type ='checkbox' name='ckItem' /></td>"
+ strTD + strRowNumber + "</td>"
+ strTD + "<select name='sel_SAPNO' style='WIDTH: 90%' value='' /></td>"
+ strTD + "<select name='sel_Description' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_Plant' style='WIDTH:94%' onchange='changedata(this.value,2);'>" + CreateSOPtion(PlantArray) + "</select></td>"
+ strTD + "<select name='sel_Stor' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_Warehouse' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_BUM' style='WIDTH: 90%'>" + CreateSOPtion(BUMArray) + "</select></td>"
+ strTD + "<select name='sel_ValuationClass' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_BOI' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_ProfitCenter' style='WIDTH: 90%' /></td>"
+ strTD + "<select name='sel_MRPCtl' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_MRPType' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_LotSize' style='WIDTH: 90%' value='' /></td>"
+ strTD + "<select name='sel_Procurement' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_Production' style='WIDTH: 90%;' value='' /></td>"
+ strTD + "<select name='sel_SupplyArea' style='WIDTH: 90%;' value=''/></td>"
+ strTD + "<select name='sel_Res' style='WIDTH: 90%' value=''/></td></tr>";
return strTemp;
}
function changedata(value,type) {
$.ajax({
type: "POST",
url: "../../PageHandle/DataHandler.ashx",
data: { plant: value },
success: function (data) {
if (data != "") {
var array = data.split("|");
if (type == 2) {
for (var i = 0; i < array.length; i++) {
// document.getElementById("ddlResourceType").options.add(new Option(text,value));
document.getElementByName("sel_Stor").options.add(new Option(array[0], value[0]));
}
}
}
}
});// $.get('../../PageHandle/DOAHandler.ashx', function (data) {
// alert(data);
// });
}
为什么红色代码部分这样写添加内容不成功呢?
该怎么获得同一个tr下的select控件并向里面添加键值对呢?
function CreateRowCopy(rowNumber) {
var strTD, strRowNumber;
strTD = "<td class='TDNormal' style='text-align:center'>";
strRowNumber = "";
if (rowNumber != null) {
strRowNumber = rowNumber.toString()
}
var strTemp = "<tr class=''>" + strTD + "<input type ='checkbox' name='ckItem' /></td>"
+ strTD + strRowNumber + "</td>"
+ strTD + "<select name='sel_SAPNO' style='WIDTH: 90%' value='' /></td>"
+ strTD + "<select name='sel_Description' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_Plant' style='WIDTH:94%' onchange='changedata(this.value,2);'>" + CreateSOPtion(PlantArray) + "</select></td>"
+ strTD + "<select name='sel_Stor' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_Warehouse' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_BUM' style='WIDTH: 90%'>" + CreateSOPtion(BUMArray) + "</select></td>"
+ strTD + "<select name='sel_ValuationClass' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_BOI' style='WIDTH: 90%'/></td>"
+ strTD + "<select name='sel_ProfitCenter' style='WIDTH: 90%' /></td>"
+ strTD + "<select name='sel_MRPCtl' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_MRPType' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_LotSize' style='WIDTH: 90%' value='' /></td>"
+ strTD + "<select name='sel_Procurement' style='WIDTH: 90%' value=''/></td>"
+ strTD + "<select name='sel_Production' style='WIDTH: 90%;' value='' /></td>"
+ strTD + "<select name='sel_SupplyArea' style='WIDTH: 90%;' value=''/></td>"
+ strTD + "<select name='sel_Res' style='WIDTH: 90%' value=''/></td></tr>";
return strTemp;
}
function changedata(value,type) {
$.ajax({
type: "POST",
url: "../../PageHandle/DataHandler.ashx",
data: { plant: value },
success: function (data) {
if (data != "") {
var array = data.split("|");
if (type == 2) {
for (var i = 0; i < array.length; i++) {
// document.getElementById("ddlResourceType").options.add(new Option(text,value));
document.getElementByName("sel_Stor").options.add(new Option(array[0], value[0]));
}
}
}
}
});// $.get('../../PageHandle/DOAHandler.ashx', function (data) {
// alert(data);
// });
}
为什么红色代码部分这样写添加内容不成功呢?
该怎么获得同一个tr下的select控件并向里面添加键值对呢?
document.getElementByName("sel_Stor").options.add(new Option(array[0], value[0]));
改成
document.getElementsByName("sel_Stor")2.document.getElementsByName返回的是一个数组,无法直接 .options, 要怎么操作你自己看吧。3.jQuery你只用来请求后台数据,太浪费了。$("#select1").append("<option value='001'>001</option>");你看这样写,给你带来了多大的方便呀。
$("#something").append("<option value='001'>001</option>");
接ls
$(this).parent().parent().find("td:eq(index)")为什么这样写不行呢?
而且,document.getElementByName("sel_Stor").options.add(new Option(array[0], value[0]));这样写会报错啊。
都跟你说了1.少一个s, 2.数组不能直接调用.options, 3. jquery可优化。
……
document.getElementsByName("sel_Stor")返回的是一个js数组,要继续调用方法是不对的,
可以拿数组中的一个元素,再调方法。