首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js 增加的opation 处于选中,该如何处理

2012-02-11 
js 增加的opation 处于选中怎么样让JS增加的opation选项是处于选中的状态?谢谢![解决办法]new Option(text

js 增加的opation 处于选中
怎么样让JS增加的opation选项是处于选中的状态?谢谢!

[解决办法]
new Option(text,value,isSelected);

for Example:
var opt = new Option( "testtext ", "testvalue ",true);
selectref.options[selectref.length] = opt;
[解决办法]
id est:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> shawl.qiu template </title>
<script type= "text/javascript ">
// <![CDATA[
onload =
function()
{
var EleSle = document.getElementById( 'hiYa ');

var iSelected = EleSle.length;
EleSle.options[EleSle.length]=fNewOpt( "selected ", 'ok ', true, true);


var iUnselected = EleSle.length
EleSle.options[EleSle.length]=fNewOpt( "unselected ", 'ok ');

alert(EleSle.options[iSelected].innerHTML+ ": "+EleSle.options[iSelected].selected)

alert(EleSle.options[iUnselected].innerHTML+ ": "+EleSle.options[iUnselected].selected)

}

function fNewOpt(sText, sValue, bDefaultSelected, bSelected)
{
return new Option(sText, sValue, bDefaultSelected, bSelected);
}
//]]>
</script>
</head>
<body>
<select id= 'hiYa '>
<option> get that </option>
</select>
</body>
</html>

热点排行
Bad Request.