-1){//說明選中}else{//說明沒有選中}2刪除被選中的項objSelect.options[objSelect.selectedIndex]=null;3增加項objSelect.options[objSelect.length]=newOption("你好","hello");4修改所選擇中的項objSelect.options[objSelect.selectedIndex" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

javascript 中關于select 的應用和相關操作

系統 2362 0
1 檢測是否有選中
if (objSelect.selectedIndex > - 1 ){
// 說明選中
} else {
// 說明沒有選中
}

2 刪除被選中的項
objSelect.options[objSelect.selectedIndex]
= null ;

3 增加項
objSelect.options[objSelect.length]
= new Option( " 你好 " , " hello " );

4 修改所選擇中的項
objSelect.options[objSelect.selectedIndex]
= new Option( " 你好 " , " hello " );

5 得到所選擇項的文本
objSelect.options[objSelect.selectedIndex].text;

6 得到所選擇項的值
objSelect.options[objSelect.selectedIndex].value;
--------------------------------動態表單、表單域個數不定的實現--------------------------------------------------------------
functioninsert(x)
{
varhtml="";
vari;
for(i=1;i
< =x ;i++)
{
html
=html +"<tr >< td > a"+i+" </ td >< td >< input name ="a" +i+""type ="text" id ="a" +i+"" /></ td ></ tr > ";
}
html="
< table border ="1" > "+html+" </ table > ";
document.getElementById("tablecontent").innerHTML=html;
}
functioncg(obj)
{
insert(obj.value);
}
在HTML中調用如下:

< form action ="" method ="post" name ="form1" id ="form1" >

< select name ="totalnum" id ="totalnum" onchange ="javascript:cg(this);" >
< option value ="10" > 10 </ option >
< option value ="2" > 2 </ option >
< option value ="50" > 50 </ option >
< option value ="100" > 100 </ option >
</ select >
< div id ="tablecontent" >
</ div >
</ form >

---------------------------通過聲明二維數組綁定SELECT下拉菜單 ----------------------------------------

< HTML >
< HEAD >
< TITLE > 動態改變下拉菜單內容示例 </ TITLE >
</ HEAD >
< SCRIPTLANGUAGE = javascript >

// 定義一個二維數組aArray,用于存放城市名稱。
var aCity = new Array();
aCity[
0 ] = new Array();
aCity[
1 ] = new Array();
aCity[
2 ] = new Array();
aCity[
3 ] = new Array();
// 賦值,每個省份的城市存放于數組的一行。
aCity[ 0 ][ 0 ] = " --請選擇-- " ;
aCity[
1 ][ 0 ] = " --請選擇-- " ;
aCity[
1 ][ 1 ] = " 廣州市 " ;
aCity[
1 ][ 2 ] = " 深圳市 " ;
aCity[
1 ][ 3 ] = " 珠海市 " ;
aCity[
1 ][ 4 ] = " 汕頭市 " ;
aCity[
1 ][ 5 ] = " 佛山市 " ;
aCity[
2 ][ 0 ] = " --請選擇-- " ;
aCity[
2 ][ 1 ] = " 長沙市 " ;
aCity[
2 ][ 2 ] = " 株州市 " ;
aCity[
2 ][ 3 ] = " 湘潭市 " ;
aCity[
3 ][ 0 ] = " --請選擇-- " ;
aCity[
3 ][ 1 ] = " 杭州市 " ;
aCity[
3 ][ 2 ] = " 蘇州市 " ;
aCity[
3 ][ 3 ] = " 溫州市 " ;
function ChangeCity()
... {
var i,iProvinceIndex;
iProvinceIndex
= document.frm.optProvince.selectedIndex;
iCityCount
= 0 ;
while (aCity[iProvinceIndex][iCityCount] != null )
iCityCount
++ ;
// 計算選定省份的城市個數
document.frm.optCity.length = iCityCount; // 改變下拉菜單的選項數
for (i = 0 ;i <= iCityCount - 1 ;i ++ ) // 改變下拉菜單的內容
document.frm.optCity[i] = new Option(aCity[iProvinceIndex][i]);
document.frm.optCity.focus();
}


</ SCRIPT >

< BODYONfocus = ChangeCity() >
< H3 > 選擇你所在的省份及城市 </ H3 >
< FORMNAME = " frm " >
< P > 省份:

< SELECTNAME = " optProvince " SIZE = " 1 " ONCHANGE = ChangeCity() >

< OPTION >-- 請選擇 --</ OPTION >

< OPTION > 廣東省 </ OPTION >

< OPTION > 湖南省 </ OPTION >

< OPTION > 浙江省 </ OPTION >

</ SELECT >
</ P >
< P > 城市:

< SELECTNAME = " optCity " SIZE = " 1 " >

< OPTION >-- 請選擇 --</ OPTION >

</ SELECT >
</ P >
</ FORM >
</ BODY >
</ HTML >

javascript 中關于select 的應用和相關操作


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 玛多县| 安平县| 道真| 凌海市| 襄樊市| 靖远县| 扎鲁特旗| 遂平县| 横山县| 贺州市| 陆丰市| 晋宁县| 丁青县| 云浮市| 巢湖市| 区。| 遂昌县| 石河子市| 双牌县| 奈曼旗| 衡山县| 满洲里市| 卫辉市| 武穴市| 崇信县| 佛学| 砀山县| 荥经县| 望奎县| 芜湖市| 兰西县| 玉田县| 怀远县| 兴隆县| 颍上县| 海盐县| 闸北区| 毕节市| 衡阳县| 香港| 东山县|