首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js怎么获得下拉菜单改变前的值

2012-04-03 
js如何获得下拉菜单改变前的值?select nameselectSS onChangeGaiBian()option value11/opti

js如何获得下拉菜单改变前的值?
<select name='selectSS' onChange="GaiBian()"><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option></select>

请问在GaiBian()这个方法里我应该怎么样获取改变前的值呀?或者用什么别的事件?

[解决办法]

HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head>  <script language="JavaScript">  <!--    function GaiBian(osel){        alert(osel.options[osel.selectedIndex].text);    }  //-->  </script> </head> <body>  <select name='selectSS' onChange="GaiBian(this)">  <option value='1'>1 </option>   <option value='2'>2 </option>   <option value='3'>3 </option>   </select>  </body></html>
[解决办法]
JScript code
var $=function(Id){    return document.getElementById(Id)?document.getElementById(Id):Id;};var $N=function(Name){    return document.getElementsByName(Name)?document.getElementsByName(Name):Name;};//获取select的值var $S=function(Id){    return $(Id).options[$(Id).selectedIndex].value;}//获取radio的值var $R=function(name){    var radio = $N(name);    var getresult = 0;    for (var i=0;i<radio.length;i++){        if(radio[i].checked)            getresult = radio[i].value;    }    return getresult;};//调用$S("select的id名")
[解决办法]
HTML code
<html><body><script type="text/javascript">var prevVal = null;window.onload = saveSel;function $(id){    return document.getElementById(id);}function saveSel(){    prevVal = $("selectSS").options[$("selectSS").selectedIndex].value;}function GaiBian(){    if(prevVal != null){        alert("选择之前的值:"+prevVal);    }    saveSel();    alert("现在的值:" + prevVal);}</script><select name='selectSS' id="selectSS" onChange="GaiBian()"> <option value='1'>1 </option> <option value='2'>2 </option> <option value='3'>3 </option> </select> </body></html>
[解决办法]
3楼可行,保存上一项的值
[解决办法]
<script language="JavaScript">
<!--
function GaiBian(obj){
alert(obj.options[obj.selectedIndex].value);
}
//-->
</script>

热点排行
Bad Request.