key words:select text值
获得select的value很容易,但是如何获得其text的内容呢,下面的代码借助了prototype.js库:
<script language="javascript">
function getSelect(selectName){
var options = $(selectName).getElementsByTagName('option');
options = $A(options);
var opt = options.find( function(employee){
return (employee.value == $F(selectName));
});
alert(opt.innerHTML);
}
</script>
<select name="hi" onchange="getSelect('hi');">
<option value="01">一</option>
<option value="02">二</option>
<option value="03">三</option>
<option value="04">四</option>
</select>
PS: $A : 转换成数组格式
opt.innerHTML:nodeText