如何用javascript改变select的options数组 设select的id为selectid用selectid.options[i].text来访问/修改各个选项的文字; 用selectid.options[i].value来访问/修改各个选项对应的值。其中的i是下标。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同意gdxy代码如下:<select id=slt1><option>option1<option>option2</select><button onclick=ChangeOptionText()>change</button><script language=javascript>function ChangeOptionText(){slt1.options[0].innerText=prompt('input first option caption:',slt1.options[0].text);}</script> <body onload="a(document.all.sel1.value);c(document.all.sel1.value,document.all.sel2.value)"><center><select name=sel1 size=1 onchange="javascript:a(this.value);"><option value="" selected>year<script><!--for(i=2001;i<=2050;i++){document.write("<option value="+i+">"+i);}//--></script></select> <select name=sel2 size=1 onchange="javascript:c(document.all.sel1.value,this.value);"><option value="" selected>month</select> <select name=sel3 size=1><option value="" selected>date</select></center><script><!--function a(b){var year=b;for(i=31;i>=1;i--){document.all.sel3.options.remove(i);}switch(b){case "":for(i=12;i>=1;i--){document.all.sel2.options.remove(i);}break;default:for(i=1;i<=12;i++){if(i<10) {i="0"+i}document.all.sel2.options[i]=new Option(i,i);}break;}}function c(d,e){var year=d;var month=e;switch(e){case "":for(i=31;i>=1;i--){document.all.sel3.options.remove(i);}break;case "01":case "03":case "05":case "07":case "08":case "10":case "12":for(j=1;j<=31;j++){if(j<10) {j="0"+j}document.all.sel3.options[j]=new Option(j,j);}break;case "04":case "06":case "09":case "11":document.all.sel3.options.remove(31);for(j=1;j<=30;j++){if(j<10) {j="0"+j}document.all.sel3.options[j]=new Option(j,j);}break;case "02":document.all.sel3.options.remove(31);document.all.sel3.options.remove(30);document.all.sel3.options.remove(29);switch(d%4){case 0:for(j=1;j<=29;j++){if(j<10) {j="0"+j}document.all.sel3.options[j]=new Option(j,j);}break;default:for(j=1;j<=28;j++){if(j<10) {j="0"+j}document.all.sel3.options[j]=new Option(j,j);}break;}}}//--></script>这是一个选择日期的脚本,自己体会! 给你个例子吧!!!<script language="javascript"><!-- function InsertSle(val1,val2,sle) { var newsle=new Option(val1,val2); sle.add(newsle); } function DelSle(sle,indexsle) { sle.options[indexsle]=null; } function DelAndIn(sle1,sle2) { for(i=0;i<sle1.length;i++) if(sle1.options[i].selected){ InsertSle(sle1.options[i].text,sle1.options[i].value,sle2); DelSle(sle1,i); } } function MoveAll(sle1,sle2) { var i=sle1.length-1; for(;i>=0;i--) { InsertSle(sle1.options[i].text,sle1.options[i].value,sle2); DelSle(sle1,i); } } innerHTML中的反斜杠连接字符串换行是不合法的? showModalDialog()如何不显示标题栏 网页另存为 在vbs中的asc函数,在js中有此功能函数么 请教高手:如何将对话框中文件类型默认为.exe 设计一个答题计时器。在线等 动态GIF图片为何不动了? 求救,关于eval的用法! 如何动态将一个JS文件添加到当前的HTML页面中? 紧急求助-----------给下拉菜单默认值. javascript是否有[Yes], [No], [Cancel]的对话框函数? 我初学javascript,我不知道如何到数据库中读取数据
代码如下:
<select id=slt1>
<option>option1
<option>option2
</select>
<button onclick=ChangeOptionText()>change</button>
<script language=javascript>
function ChangeOptionText()
{
slt1.options[0].innerText=prompt('input first option caption:',slt1.options[0].text);
}
</script>
<center>
<select name=sel1 size=1 onchange="javascript:a(this.value);">
<option value="" selected>year
<script>
<!--
for(i=2001;i<=2050;i++)
{
document.write("<option value="+i+">"+i);
}
//-->
</script>
</select>
<select name=sel2 size=1 onchange="javascript:c(document.all.sel1.value,this.value);">
<option value="" selected>month
</select>
<select name=sel3 size=1>
<option value="" selected>date
</select>
</center>
<script>
<!--
function a(b)
{
var year=b;
for(i=31;i>=1;i--)
{
document.all.sel3.options.remove(i);
}
switch(b)
{
case "":
for(i=12;i>=1;i--)
{
document.all.sel2.options.remove(i);
}
break;
default:
for(i=1;i<=12;i++)
{
if(i<10) {i="0"+i}
document.all.sel2.options[i]=new Option(i,i);
}
break;
}
}
function c(d,e)
{
var year=d;
var month=e;
switch(e)
{
case "":
for(i=31;i>=1;i--)
{
document.all.sel3.options.remove(i);
}
break;
case "01":
case "03":
case "05":
case "07":
case "08":
case "10":
case "12":
for(j=1;j<=31;j++)
{
if(j<10) {j="0"+j}
document.all.sel3.options[j]=new Option(j,j);
}
break;
case "04":
case "06":
case "09":
case "11":
document.all.sel3.options.remove(31);
for(j=1;j<=30;j++)
{
if(j<10) {j="0"+j}
document.all.sel3.options[j]=new Option(j,j);
}
break;
case "02":
document.all.sel3.options.remove(31);
document.all.sel3.options.remove(30);
document.all.sel3.options.remove(29);
switch(d%4)
{
case 0:
for(j=1;j<=29;j++)
{
if(j<10) {j="0"+j}
document.all.sel3.options[j]=new Option(j,j);
}
break;
default:
for(j=1;j<=28;j++)
{
if(j<10) {j="0"+j}
document.all.sel3.options[j]=new Option(j,j);
}
break;
}
}
}
//-->
</script>
这是一个选择日期的脚本,自己体会!
<!--
function InsertSle(val1,val2,sle)
{
var newsle=new Option(val1,val2);
sle.add(newsle);
}
function DelSle(sle,indexsle)
{
sle.options[indexsle]=null;
}
function DelAndIn(sle1,sle2)
{
for(i=0;i<sle1.length;i++)
if(sle1.options[i].selected){
InsertSle(sle1.options[i].text,sle1.options[i].value,sle2);
DelSle(sle1,i);
}
}
function MoveAll(sle1,sle2)
{
var i=sle1.length-1;
for(;i>=0;i--)
{
InsertSle(sle1.options[i].text,sle1.options[i].value,sle2);
DelSle(sle1,i);
}
}