国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JavaScript與DropDownList 區別分析

2024-05-06 14:12:01
字體:
來源:轉載
供稿:網友
比如<asp:LinkButton>控件就被渲染成了<a>錨點控件,這里要講的DropDownList控件也一樣,被渲染成了普通的select控件,在如下的asp.net頁面中定義了一個web服務器控件DropDownList和一個普通的select控件(主要為了對比)。
代碼
代碼如下:
<asp:DropDownList ID = "ddlCities" runat = "server">
<asp:ListItem Value = "0">長沙</asp:ListItem>
<asp:ListItem Value = "1">北京</asp:ListItem>
<asp:ListItem Value = "2">天津</asp:ListItem>
<asp:ListItem Value = "3">漠河</asp:ListItem>
</asp:DropDownList>
<select id = "ddlNames" runat ="server">
<option value = "0">James</option>
<option value = "1">Green</option>
<option value = "2">Lily</option>
<option value = "3">Lucy</option>
</select>

  在瀏覽器中查看該頁面,并點擊查看源文件,不難看出,asp.net頁面被渲染成了如下格式:
代碼
代碼如下:
<select name="ddlCities" id="ddlCitys">
<option value="0">長沙</option>
<option value="1">北京</option>
<option value="2">天津</option>
<option value="3">漠河</option>
</select>
<select name="ddlNames" id="ddlNames">
<option value="0">James</option>
<option value="1">Green</option>
<option value="2">Lily</option>
<option value="3">Lucy</option>
</select>

  好了,接下來介紹一下要用javascript操縱DropDownList控件,首先得了解select(或者DropDownList)的兩個最基本的屬性,一個是value屬性,一個是text屬性,還有一個selectedIndex屬性,用來標識當前選中的項(數字),具體可參見上面的示例代碼。
下面正式言歸正傳,主要介紹如下幾點:
(1) 清空DropDownList控件中的值。
  
document.getElementById('ddlCities').options.length = 0;
(2) 判斷DropDownList中是否有value為'Param1'的ListItem。
代碼如下:
function isListItemExist(objDdl , objItemValue)
{
var isExist = false;
for(var i in objSelect.options)
  {
    if(i.value == objItemValue)
    {
      isExist = true;
      break;
    }
  }
  return isExist;
}

JavaScript與DropDownList
服務器控件DropDownList和Javascript的之間的傳遞
代碼如下:
<script language="javascript">
function hehe()
{
document.all('txtSdept').value =document.all('ddlSdept').options[document.all('ddlSdept').selectedIndex].text;
}
</script>
<asp:DropDownList id="ddlSdept" style="Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 112px" onchange="hehe()" runat="server">
<asp:ListItem Value="1">計算機系</asp:ListItem>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 高密市| 绩溪县| 綦江县| 凤翔县| 玛曲县| 娄底市| 稷山县| 瑞昌市| 乌拉特前旗| 司法| 忻州市| 镇巴县| 黄平县| 牡丹江市| 毕节市| 六盘水市| 德格县| 安宁市| 缙云县| 和田县| 乐清市| 莱芜市| 龙里县| 景洪市| 昭平县| 晴隆县| 自贡市| 阜宁县| 图们市| 阿克陶县| 林西县| 望江县| 城固县| 塔河县| 双峰县| 天台县| 克东县| 宁河县| 东港市| 沽源县| 都兰县|