[英]drop down box using jquery
I have two drop down boxes.One drop box has values as may the other as 1.Now i change the first drop down value to june but will not change second drop box value.Here it is not passing second drop box because i have initiated using click event.Here i use live(click)but do i do that w/o clicking 2nd drop box that value should also pass我有两个下拉框。一个下拉框的值可能与另一个一样为 1。现在我将第一个下拉值更改为 6 月,但不会更改第二个下拉框值。这里它没有通过第二个下拉框,因为我已经启动使用点击事件。在这里我使用实时(点击)但我是否这样做没有点击第二个下拉框,该值也应该通过
**Updated**
$(firstselect).live(click,function)
$(secondselect).live(click,function)
Now that I understood the problem:现在我明白了这个问题:
The second select box should show the value that was previously selected in the first one.
第二个 select 框应显示先前在第一个框中选择的值。
You could do like so:你可以这样做:
var prevValue = $('#firstselect').val();
$('#firstselect').change(function() {
$('#secondselect').val(prevValue);
prevValue = this.value;
});
Bidirectional:双向:
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.