日期:2014-05-16  浏览次数:20424 次

如何取得下拉框 onchang之前的值
如何取得下拉框   onchang之前的值

------解决方案--------------------
页面加载的时候就用全局变量保存 window.old_sel_value = sel.options[sel.selectedIndex].value
onchange 函数最后再保存下,随时可以取window.old_sel_value

------解决方案--------------------
随便写了一个,看看够用不?

用动态属性实现,跟踪每次变化,至于初始值可以用 hookee() 的方法来实现。

L@_@K

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> new document </title>
<meta name= "generator " content= "editplus " />
<meta name= "author " content= " " />
<meta name= "keywords " content= " " />
<meta name= "description " content= " " />
</head>

<body>
<select id= "selCars " size= "1 ">
<option value= "0 "> - 请选择 - </option>
<option value= "1 "> 宝马 </option>
<option value= "2 "> 保时捷 </option>
<option value= "3 "> 奔驰 </option>
</select>
<div id= "divOutput ">

</div>
<script type= "text/javascript ">
<!--
var oOutput = document.getElementById( "divOutput ");
var oSel = document.getElementById( "selCars ");

oSel.onchange = function ()
{
oOutput.innerHTML += "之前选中: " + this.options[this.previousSelectedIndex].text + " ; " + "当前选中: " + this.options[this.selectedIndex].text + ". <br /> ";
};

oSel.onfocus = function ()
{
this.previousSelectedIndex = this.selectedIndex;
};

oSel.onclick = function ()
{
this.previousSelectedIndex = this.selectedIndex;
};

oSel.onkeyup = function ()
{
this.previousSelectedIndex = this.selectedIndex;
};

//-->
</script>
</body>
</html>