js 默认选中select 选项

<select id="HDname" style="width: 150px;">
<option value="0">请选择</option>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<option value="<%#Eval("code") %>"><%#Eval("name") %></option>
</ItemTemplate>

</asp:Repeater>
</select>

<script>
var code = "<%=name%>";

if (code != "") {
setHDname(code);
}
//document.writeln(document.getElementById("sel").options.length);

//document.writeln(document.getElementById("sel")["options"].length);

//document.writeln(document.getElementById("sel").children.length);

function setHDname(code) {
var s1 = document.getElementById("HDname");

for (i = 0; i <= s1.options.length; i++) {
if (s1.options[i].value == code) {
s1.options[i].selected = true;
}

}
}
</script>

上一篇:linux命令汇总1


下一篇:JPEG