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

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

javascript 中關(guān)于select 的應(yīng)用和相關(guān)操作

系統(tǒng) 2337 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;
--------------------------------動態(tài)表單、表單域個數(shù)不定的實現(xiàn)--------------------------------------------------------------
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中調(diào)用如下:

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

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

< HTML >
< HEAD >
< TITLE > 動態(tài)改變下拉菜單內(nèi)容示例 </ TITLE >
</ HEAD >
< SCRIPTLANGUAGE = javascript >

// 定義一個二維數(shù)組aArray,用于存放城市名稱。
var aCity = new Array();
aCity[
0 ] = new Array();
aCity[
1 ] = new Array();
aCity[
2 ] = new Array();
aCity[
3 ] = new Array();
// 賦值,每個省份的城市存放于數(shù)組的一行。
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
++ ;
// 計算選定省份的城市個數(shù)
document.frm.optCity.length = iCityCount; // 改變下拉菜單的選項數(shù)
for (i = 0 ;i <= iCityCount - 1 ;i ++ ) // 改變下拉菜單的內(nè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 中關(guān)于select 的應(yīng)用和相關(guān)操作


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 肃宁县| 奎屯市| 鹤山市| 兰考县| 新疆| 湘乡市| 永福县| 卓尼县| 兴安县| 公主岭市| 泾川县| 乡城县| 平和县| 梨树县| 宝兴县| 新巴尔虎右旗| 抚顺县| 德州市| 石楼县| 富裕县| 康平县| 石家庄市| 民勤县| 甘泉县| 喀什市| 新和县| 山丹县| 鹤峰县| 三门峡市| 安阳县| 普陀区| 肇东市| 高阳县| 彰化县| 成都市| 珲春市| 高邑县| 都昌县| 青海省| 沙洋县| 阜康市|