首页 > 代码库 > js 获取select选中值
js 获取select选中值
method1:
<form name="f1">
<label id="lbl2">xxx</label>
<select id="pro1">
<option selected>添加项目</option>
<option onClick="pro1()">1</option>
<option onClick="pro1()">2</option>
<option onClick="pro1()">3</option>
</select>
</form>
<script>
function pro1(){
var pro1=document.getElementById("pro1");
var lbl2=document.getElementById("lbl2");
var val=pro1.selectedIndex;
lbl2.innerHTML=pro1[val].value;
}
</script>
method2:
<form name="frm">
<input type=checkbox name=item value=http://www.mamicode.com/1 onclick="choseItem();">
a
<input type=checkbox name=item value=http://www.mamicode.com/2 onclick="choseItem();">
b
<input type=checkbox name=item value=http://www.mamicode.com/3 onclick="choseItem();">
c
<input type=checkbox name=item value=http://www.mamicode.com/4 onclick="choseItem();">
d
<input type=text name="txt" id="txt">
</form>
<input type=button value="http://www.mamicode.com/关闭" onclick="foo();">
<script>
function choseItem()
{
var v="";
var check_item = document.frm.item;
for(i=0;i<check_item.length;i++)
{
if(check_item[i].checked)
{
v+=","+check_item[i].value;
}
document.frm.txt.value=http://www.mamicode.com/v.replace(/^,{1}/,"");
}
}
function foo()
{
window .close();
window .opener.document.getElementById("txt0").value=http://www.mamicode.com/document.getElementById("txt").value
}
</script>
js 获取select选中值