87,993
社区成员
发帖
与我相关
我的任务
分享
<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='txt3' />
<input type='button' value=' = ' id="js"/>
<input type='text' id='jg' />
<script type="text/javascript">
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("select");
var txt3 = document.getElementById("txt3");
var js = document.getElementById("js");
var jg = document.getElementById("jg");
js.onclick = function(){
var opt = txt2.options[txt2.selectedIndex].value;
if(opt=="+"){
jg.value = parseInt(txt1.value) + parseInt(txt3.value);
}
else if(opt=="-"){
jg.value = parseInt(txt1.value) - parseInt(txt3.value);
}
else if(opt=="*"){
jg.value = parseInt(txt1.value) * parseInt(txt3.value);
}
else{
jg.value = parseInt(txt1.value) / parseInt(txt3.value);
}
}
</script>
请问还有其它获取选中值的方法吗 我之前写过一个类似的 但是不是像4楼写的那样 4楼那个确实可以