如何使用 Javascript 从下拉列表中获取先前选定的项目和当前选定的项目?我认为,使用几个隐藏字段并在其中存储先前和当前值。更改下拉列表值时,将当前隐藏字段值复制到上一个。隐藏字段值,然后用选定的下拉值替换当前隐藏字段值。但我是 jquery 的新手。所以我不知道如何在上述条件下工作。任何人都知道 Jquery 意味着回答我。
			
			1207 次
		
2 回答
            2        
        
		
对于当前选定的项目,这应该可以工作
var yourSelect = document.getElementById('id');
alert(yourSelect.options[yourSelect.selectedIndex].value)
对于以前的
<select name="test">
    <option value="test1">test1</option>
    <option value="test2">test2</option>
    <option value="test3">test3</option>
    <option value="test4">test4</option>
</select>
(function () {
    var previous;
    $("select[name=test]").focus(function () {
        // Store the current value on focus, before it changes
        previous = this.value;
    }).change(function() {
        // Do soomething with the previous value after the change
        document.getElementById("log").innerHTML = "<b>Previous: </b>"+previous;
        previous = this.value;
    });
})();
于 2013-04-05T09:42:37.343   回答
    
    
            1        
        
		
使用以下:
document.getElementById("ddlcountry").options[document.getElementById("ddlcountry").selectedIndex].value
于 2013-04-30T05:33:50.283   回答