这是我写的一段关于两个下拉菜单联动的JS代码,targForm.selName和targForm.selCompany是<select id="selName" onchange="CreateClassID(this.form)"></select> 和<select id="selCompany"></select> ,我想问下,如果有一个 <asp:HiddenField ID="HDFThirdComponentID" runat="server" Value='<%# Bind("ThirdComponentID") %>' />,以上这些都在一个GridView控件中。
我想加载时,<select id="selName" onchange="CreateClassID(this.form)"></select>加载完所有选项后,显示的当前选项是select中的value等于HiddenField中Value值的那一项,这样的话,JS中应该怎么写?
function CreateRootID(targForm) {
var targ = targForm.selName;
for (i = 0; i < ThirdComponent.length; i++) { targ.options[i] = new Option(ThirdComponent[i][1], ThirdComponent[i][0]);
}
}
function CreateClassID(targForm) {//生成二级分类 targForm为目标表单
var parent = targForm.selName;
var subfield = targForm.selCompany;
var classid;
classid = parent.options[parent.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('二级分类', '-1');
for (i = 0; i < ThirdCompany.length; i++) {
if (ThirdCompany[i][2] == classid) {
subfield.options[subfield.length] = new Option(ThirdCompany[i][1], ThirdCompany[i][0])
}
}
}
我想加载时,<select id="selName" onchange="CreateClassID(this.form)"></select>加载完所有选项后,显示的当前选项是select中的value等于HiddenField中Value值的那一项,这样的话,JS中应该怎么写?
function CreateRootID(targForm) {
var targ = targForm.selName;
for (i = 0; i < ThirdComponent.length; i++) { targ.options[i] = new Option(ThirdComponent[i][1], ThirdComponent[i][0]);
}
}
function CreateClassID(targForm) {//生成二级分类 targForm为目标表单
var parent = targForm.selName;
var subfield = targForm.selCompany;
var classid;
classid = parent.options[parent.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('二级分类', '-1');
for (i = 0; i < ThirdCompany.length; i++) {
if (ThirdCompany[i][2] == classid) {
subfield.options[subfield.length] = new Option(ThirdCompany[i][1], ThirdCompany[i][0])
}
}
}
解决方案 »
- 请教如何才能把数据表中的两个字段值赋给dropdownlist的DataTextField?
- 为什么我用dw在html中插入一个.gif(当然是会动的动画),可一运行就动不了,就变成静的图片了?高手们,???Who can answer me
- repeater控件如何绑定图片?
- 初级问题:Datagrid中的模版控件,如何绑定到处理函数?
- 在线详求:如何在Aspnet页面中加入Flash文件?
- 是不是每个项目都要写存储过程呀?
- 有关SqlHelper
- dropdownlist级联菜单问题
- 请教DropDownList的插入数据库问题
- 新装了framework正式版,显示其自带的asp.net quickstart tutorial有问题
- 菜鸟问题-request
- 前台数据的显示
var choose = o.parentNode.getElementsByTagName("select");
alert(choose[0].options[choose[0].selectedIndex].value);
<head><title></title>
<script language="javascript">
function $(s)
{
return document.getElementById(s);
}
function InitSel(id)
{
var i;
for(i=0;i<$("selone").options.length;i++)
{
if($('selone').options[i].value == id)
{
$('selone').options[i].selected = true;
}
}
}
</script>
</head>
<body onload="InitSel('b');">
<select id="selone">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</body>
</html>