<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>

js 默认选中select 选项的更多相关文章

  1. HTML中的<select>标签如何设置默认选中的选项

    方法有两种. 第一种通过<select>的属性来设置选中项,此方法可以在动态语言如php在后台根据需要控制输出结果. 1 2 3 4 5 < select  id =  " ...

  2. js进阶 9-11 select选项框如何动态添加和删除元素

    js进阶 9-11 select选项框如何动态添加和删除元素 一.总结 一句话总结: 二.js进阶 9-11 select选项框如何动态添加和删除元素 1.案例说明 2.相关知识 Select 下拉列 ...

  3. js 默认选中分页条件项

    <table border="0" cellspacing="0" cellpadding="0" height="100% ...

  4. js中的new Option默认选中

    new Option("文本","值",true,true).后面两个true分别表示默认被选中和有效! //js默认选中 var sel = document ...

  5. pyQT Dialog默认选中某一个选项问题的解决

    方法一: 在新建ui文件时不要新建Dialog # -*- coding: utf-8 -*- # Form implementation generated from reading ui file ...

  6. jQuery实现下拉框默认选中

    <form class="form-inline" method="post" action="/score_result/"> ...

  7. 修改select下拉选的默认选中值

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  8. struts2设置<s:select>默认选中项的方法

    struts2的select标签中,常用的有以下几个属性:(1)struts2中的select 标签中,必须设置的属性只有一个,即是list.(2)select标签的list中必须有值,不然会报错.如 ...

  9. jQuery 设置select默认选中问题

    在进行其他操作后,恢复select默认选中 html代码: <select id="shai" style="width:150px;margin:5px 50px ...

随机推荐

  1. 【转】用树莓派搭建web服务器

    本文将详细介绍如何在树莓派上配置服务器,和<教你在Xubuntu上搭建LAMP服务器>有些类似,多了一些介绍在树莓派上的不同步骤的地方. 这种服务器的配置被称为LAMP,是最流行的服务器配 ...

  2. .NET 可空值类型

    Microsoft在CLR中引入了可空值类型(nullable value type)的概念. FCL中定义System.Nullable<T>类如下: [Serializable,Str ...

  3. VS2013修改MVC4默认生成的模板

    找到以下目录,根据VS版本和安装目录不同相应改动: I:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTempla ...

  4. 设计模式:职责链模式(Chain Of Responsibility)

    定  义:使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递请求,直到有一个对象处理它为止. 结构图: 处理请求类: //抽象处理类 abs ...

  5. Wordpress添加关键词和描述

    找到主题的header.php文件,然后在其<head>标签内加入加一下代码: 详细版 <?php $description = ''; $keywords = ''; if (is ...

  6. Magento Error – The directory is not writable by server.

    When trying to use the insert image functionality in Magento if you receive an error saying: “The di ...

  7. php创建网站问题

    网站在本地浏览的时候链接点击都提示The requested URL was not found on this server. 本地装的wamp,apache和php.ini都是好的 最后更改: 在 ...

  8. C#连接数据库的四种方法(转)

    C#连接数据库的四种方法 在进行以下连接数据库之前,请先在本地安装好Oracle Client,同时本次测试System.Data的版本为:2.0.0.0. 在安装Oracle Client上请注意, ...

  9. sql Server 使某一列的值等于行号

    declare @i INT update 表名 SET [列名]=@i,@i=@i+ WHERE 条件

  10. 脚本编程中的test、bash调试、变量计算、参数

    脚本编程中的test.bash调试.变量计算.参数 1.文件测试 -e FILE:测试文件是否存在 -f FILE:测试文件是否为普通文件 -d FILE:测试路径是否为目录 -r FILE:测试当前 ...