[英]drop down box using jquery
我有兩個下拉框。一個下拉框的值可能與另一個一樣為 1。現在我將第一個下拉值更改為 6 月,但不會更改第二個下拉框值。這里它沒有通過第二個下拉框,因為我已經啟動使用點擊事件。在這里我使用實時(點擊)但我是否這樣做沒有點擊第二個下拉框,該值也應該通過
**Updated**
$(firstselect).live(click,function)
$(secondselect).live(click,function)
現在我明白了這個問題:
第二個 select 框應顯示先前在第一個框中選擇的值。
你可以這樣做:
var prevValue = $('#firstselect').val();
$('#firstselect').change(function() {
$('#secondselect').val(prevValue);
prevValue = this.value;
});
雙向:
var prevValue = {
'firstselect': $('#firstselect').val(),
'secondselect': $('#secondselect').val()
};
$('select').change(function() {
var other = this.id === 'firstselect' ? 'secondselect' : 'firstselect';
prevValue[other] = $('#' + other).val();
$('#' + other).val(prevValue[this.id]);
prevValue[this.id] = this.value;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.