日期:2014-05-16 浏览次数:20503 次
<!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>
------解决方案--------------------
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>
<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>