帮忙解决一个2级联动的问题,下来框怎么清空!!!
时间:2010-09-28
来源:互联网
页面:
国家: <select style= "width:100px; " id= "drop_guojia " name= "guojia " onchange= "select1_onchange() "> </select>
地区: <select id= "drop_diqu " name= "diqu " style= "width:100px; "> </select>
js:
function select1_onchange()
{
debugger;
createXmlHttpRequest();
var name = document.getElementById( "drop_guojia ").value;
var url = "WebService.asmx/GetData2?cityID= "+escape(name);
xmlHttp.open( "GET ",url,true);
xmlHttp.onreadystatechange = requestXMLHttp1;
xmlHttp.send(null);
}
function requestXMLHttp1()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var rootNode = xmlHttp.responseXML.documentElement;
for(var i = 0;i <rootNode.childNodes.length;i++)
{
document.getElementById( "drop_diqu ").length = 1;
document.getElementById( "drop_diqu ").options[0].selected = true;
var value = rootNode.childNodes[i].childNodes[0].firstChild.nodeValue;
var text = rootNode.childNodes[i].childNodes[1].firstChild.nodeValue;
var opt = new Option();
opt.value = value;
opt.text = text;
document.getElementById( "drop_diqu ").options.add(opt);
}
}
}
}
当我第一个下拉框触发select1_onchange()事件的时候,第二个下拉框的值怎么清空,要不然,它会把原来的跟现在选择的累加起来,
我在循环里面加了一句document.getElementById( "drop_diqu ").length = 1;但只有一条记录了,要怎么解决,怎么清空他。
只显示属于我选择第一个下拉框下面的值。
谢谢,各位帮忙解决下
国家: <select style= "width:100px; " id= "drop_guojia " name= "guojia " onchange= "select1_onchange() "> </select>
地区: <select id= "drop_diqu " name= "diqu " style= "width:100px; "> </select>
js:
function select1_onchange()
{
debugger;
createXmlHttpRequest();
var name = document.getElementById( "drop_guojia ").value;
var url = "WebService.asmx/GetData2?cityID= "+escape(name);
xmlHttp.open( "GET ",url,true);
xmlHttp.onreadystatechange = requestXMLHttp1;
xmlHttp.send(null);
}
function requestXMLHttp1()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var rootNode = xmlHttp.responseXML.documentElement;
for(var i = 0;i <rootNode.childNodes.length;i++)
{
document.getElementById( "drop_diqu ").length = 1;
document.getElementById( "drop_diqu ").options[0].selected = true;
var value = rootNode.childNodes[i].childNodes[0].firstChild.nodeValue;
var text = rootNode.childNodes[i].childNodes[1].firstChild.nodeValue;
var opt = new Option();
opt.value = value;
opt.text = text;
document.getElementById( "drop_diqu ").options.add(opt);
}
}
}
}
当我第一个下拉框触发select1_onchange()事件的时候,第二个下拉框的值怎么清空,要不然,它会把原来的跟现在选择的累加起来,
我在循环里面加了一句document.getElementById( "drop_diqu ").length = 1;但只有一条记录了,要怎么解决,怎么清空他。
只显示属于我选择第一个下拉框下面的值。
谢谢,各位帮忙解决下
作者: qqiilrain 发布时间: 2010-09-28
jquery语法:obj.children().remove();
js的不知道,等楼下高手。。。
js的不知道,等楼下高手。。。
作者: yuxh81 发布时间: 2010-09-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28