<!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
>
select选中js版本
</
title
>
</
head
>
<
body
>
<
select
id
=
"selectId"
>
<
option
value
=
""
>
请选择
</
option
>
<
option
value
=
"1"
>
test1
</
option
>
<
option
value
=
"2"
>
test2
</
option
>
<
option
value
=
"3"
>
test3
</
option
>
<
option
value
=
"4"
>
test4
</
option
>
<
option
value
=
"5"
>
test5
</
option
>
</
select
>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
/**
* js选中select中指定项
*
@param
string id : select的id值
*
@param
string key : select的value值
*/
function
selectMenu(id, value)
{
var
objSelect = document.getElementById(id);
var
length = objSelect.options.length;
for
(
var
i=0; i<length; i++)
{
if
(objSelect.options[i].value == value)
{
objSelect.options[i].selected =
true
;
break
;
}
}
}
selectMenu(
'selectId'
, 3);
</
script
>
</
body
>
</
html
>