取得select的option的text值
<html>
<head>
<title>Option对象的属性</title>
<script language="JavaScript">
// 显示选项信息
function optionData(){
var objSelect = document.myForm.mySelect;
pos.innerText = objSelect.options[objSelect.selectedIndex].index;
content.innerText = objSelect.options[objSelect.selectedIndex].text;
show.innerText = objSelect.options[objSelect.selectedIndex].value;
}
// 更改选项名称
function changeText(objForm){
var objSelect = objForm.mySelect
objSelect.options[objSelect.selectedIndex].text = objForm.optionName.value;
}
</script>
</head>
<body>
<h2>Option对象的属性</h2>
<hr>
<form name="myForm">
<select name="mySelect">
<option value="value1" Selected>HTML</option>
<option value="value2">JavaScript</option>
<option value="value3">VBScript</option>
</select>
<input type="button" onclick="optionData()" value="选择"><br>
选项名称 : <input type="text" name="optionName">
<input type="button" onclick="changeText(this.form)" value="更改">
</form>
选项位置: <span id="pos"></span><br>
选项名称: <span id="content"></span><br>
选项值 : <span id="show"></span><br>
</body>
</html>
<head>
<title>Option对象的属性</title>
<script language="JavaScript">
// 显示选项信息
function optionData(){
var objSelect = document.myForm.mySelect;
pos.innerText = objSelect.options[objSelect.selectedIndex].index;
content.innerText = objSelect.options[objSelect.selectedIndex].text;
show.innerText = objSelect.options[objSelect.selectedIndex].value;
}
// 更改选项名称
function changeText(objForm){
var objSelect = objForm.mySelect
objSelect.options[objSelect.selectedIndex].text = objForm.optionName.value;
}
</script>
</head>
<body>
<h2>Option对象的属性</h2>
<hr>
<form name="myForm">
<select name="mySelect">
<option value="value1" Selected>HTML</option>
<option value="value2">JavaScript</option>
<option value="value3">VBScript</option>
</select>
<input type="button" onclick="optionData()" value="选择"><br>
选项名称 : <input type="text" name="optionName">
<input type="button" onclick="changeText(this.form)" value="更改">
</form>
选项位置: <span id="pos"></span><br>
选项名称: <span id="content"></span><br>
选项值 : <span id="show"></span><br>
</body>
</html>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。