selectObject.value这个属性返回的是什么


<!DOCTYPE html>    
<html>    
<head>    
<title> new document </title>      
<script type="text/javascript">    
function count(){    
var txt1   = parseInt( document.getElementById('txt1').value);//鑾峰彇绗竴涓緭鍏ユ鐨勫€�    
var txt2   = parseInt( document.getElementById('txt2').value);//鑾峰彇绗簩涓緭鍏ユ鐨勫€�    
var select = document.getElementById('select').value;//鑾峰彇閫夋嫨妗嗙殑鍊�    
var result = '';    
switch (select)    
{    
case '+':    
result = txt1 + txt2;    
break;    
case '-':    
result = txt1 - txt2;    
break;    
case '*':    
result = txt1 * txt2;    
break;    
case '/':    
result = txt1 / txt2;    
break;    
}    
document.getElementById('fruit').value = result;
}    
</script>     
</head>     
<body>    
<input type='text' id='txt1' />     
<select id='select'>    
<option value='+'>+</option>    
<option value="-">-</option>    
<option value="*">*</option>    
<option value="/">/</option>    
</select>    
<input type='text' id='txt2' />     
<input type='button' value='  =  '  onclick = "count()" />     
<input type='text' id='fruit' />       
</body>    
</html>

第一个问题 想问一下 为什么var select = document.getElementById('select').value;一定要后面有.value; 代表什么意思?

第二个问题我在w3c那个网站里面看了一下关于select这个标签 没有找到它有value这个属性 请问是因为w3c并不是所有属性都会罗列出来的关系嘛?

谢谢!

Beckybei
浏览 1392回答 1
1回答

荼酒

1.去拿option的值然后进行switch循环遍历判断.2.这样写是对的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript