1

简要解释我的程序:

我有 3 个选择框

如果用户在第一个框中选择的值是 2 并且用户在第二个框中选择的值是 3(选项值),那么第三个选择框应该显示一个数组。

此代码不起作用,但显示了一个想法:

if ($('#firstbox').click(function() { ($(this).val() == '2'); } &&    
    $('#secondbox').click(function() { ($(this).val() == '3'); }) {
    // Array Display here (not included the coding here, because there is no issue with this coding.. seems working fine)
}

我需要有关 if 语句和 && 操作中包含的代码的帮助,以检查表达式。

4

4 回答 4

1
var select1 = $('#firstbox');
var select2 = $('#secondbox');

$([select1, select2]).change(function () {
    if ( select1.val() == 2 && select2.val() == 3 ) {
        // run your code here...
    }
});
于 2013-02-11T19:19:35.377 回答
0

您需要将点击事件绑定到第三个选择框或绑定到前两个框的更改事件并回调一个更新第三个框的通用函数。

于 2013-02-11T19:19:37.367 回答
0
$("#firstbox, #secondbox").change(UpdateThird);

function UpdateThird() {
    var a = $("#firstbox").val();
    var b = $("#secondbox").val();
    if (a == 2 && b == 3) {
        // ...
    }
}
于 2013-02-11T19:25:25.717 回答
0

假设

<select id="firstbox">
  <option value="1">1</option>  
  <option value="2">2</option>
  <option value="3">3</option>
</select>
<select id="secondbox">
  <option value="1">1</option>  
  <option value="2">2</option>
  <option value="3">3</option>
</select>

脚本:

$('#secondbox, #firstbox').on('change',function(){
  if($('#firstbox').val() == 2 && $('#secondbox').val() == 3)
    alert('array display code here...');
})
于 2013-02-11T19:29:10.553 回答