在html中我建了一个select下拉菜单,然后通过js来操作document节点,给select下拉菜单添加选项,方法如下:var models = document.getElementById("major");
var results = xmlHttp.responseXML.getElementsByTagName("major_name");
if(results.length>0){
clearElement("major");
var option = null;
option = document.createElement("option");
option.appendChild(document.createTextNode("-----"));
models.appendChild(option);
for(var i=0;i<results.length;i++){
option = document.createElement("option");
option.appendChild(document.createTextNode(results[i].firstChild.nodeValue));
models.appendChild(option);
}
}这样我把选项的文字部分给弄出来了,但是我需要设置选项的value值,请问能在这里修改吗?
求指导&………………
var results = xmlHttp.responseXML.getElementsByTagName("major_name");
if(results.length>0){
clearElement("major");
var option = null;
option = document.createElement("option");
option.appendChild(document.createTextNode("-----"));
models.appendChild(option);
for(var i=0;i<results.length;i++){
option = document.createElement("option");
option.appendChild(document.createTextNode(results[i].firstChild.nodeValue));
models.appendChild(option);
}
}这样我把选项的文字部分给弄出来了,但是我需要设置选项的value值,请问能在这里修改吗?
求指导&………………
models.options.add(varItem);
//得到节点信息
var cityDom = document.getElementById("subtype");
//向下拉列表添加内容
//创建元素
var city = document.createElement("option");
//设置其value
city.setAttribute("value",code);
//添加显示的文本值
city.appendChild(document.createTextNode(name));
//添加到DOM中
cityDom.appendChild(city);
如果你的value没有设置值的话,用request.getParameter()只能得到null
能够在后面修改其value吗?