📄 tu6.17.htm
字号:
<HTML>
<HEAD>
<TITLE>使用 option 对象的属性</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function display(myForm)
{
newWin=open("","","width=300,height=300")
newWin.document.write("<H3>选项菜单中的选项属性如下:</H3>")
for(i=0;i<document.form1.myList.length;i++)
{
if(document.form1.myList.options[i].defaultSelected==true)
{ j=i+1;
newWin.document.write("默认选中的选项为第 "+j+" 项。<P>")
}
if(document.form1.myList.options[i].selected==true)
{ j=i+1;
newWin.document.write("当前选中的选项为第 "+j+" 项;<BR>")
newWin.document.write("其文本为' "+document.form1.myList.options[i].text+"'。<BR>")
newWin.document.write("其值为' "+document.form1.myList.options[i].value+"'。<BR>")
}
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<H3>选项菜单示例</H3>
<FORM NAME=form1>
<SELECT name=myList>
<OPTION VALUE=opt1>选项 1
<OPTION VALUE=opt2 SELECTED>选项 2
<OPTION VALUE=opt3>选项 3
<OPTION VALUE=opt4>选项 4
</SELECT><P>
单击以下按钮显示当前选项菜单的选项信息:<P>
<INPUT type=button value="显示信息" onclick=display(this.form)>
</FORM>
</DIV>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -