日期:2014-05-16  浏览次数:20407 次

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>