gpt4 book ai didi

javascript - jQuery 验证插件 - 比较两个选择下拉列表的自定义方法

转载 作者:行者123 更新时间:2023-11-28 01:44:46 24 4
gpt4 key购买 nike

我有这两种选择类型的 HTML:

<label for="h_slat_type">Slat Type</label>
<select name="h_slat_type" id="h_slat_type">
<option disabled="disabled" selected>Select</option>
<option disabled="disabled">---------</option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
</select>

<label for="v_slat_type">Slat Type</label>
<select name="v_slat_type" id="v_slat_type">
<option disabled="disabled" selected>Select</option>
<option disabled="disabled">---------</option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
</select>

验证失败的条件是当我将 h_slat_typev_slat_type 设置为 2 时。

换句话说,如果:

h_slat_type 1 = v_slat_type 1 -> true

h_slat_type 2 = v_slat_type 1 -> true

h_slat_type 1 = v_slat_type 2 -> true

h_slat_type 2 = v_slat_type 2 -> false

JS方法:

jQuery.validator.addMethod("typecheck", function(value, element) {
return ($('#h_slat_type').val() == $('#v_slat_type').val());
}, "Horizontal Type 2 and Vertical Type 2 incompatible!");

在这种情况下什么会起作用? ty 虚拟机。

最佳答案

试试这个:

    if($('#h_slat_type').val() == $('#v_slat_type').val())
return true;
else if ($('#h_slat_type').val()==1 && $('#v_slat_type').val()==2)
return true;
else if ($('#h_slat_type').val()==2 && $('#v_slat_type').val()==1)
return true;
else
return false;

关于javascript - jQuery 验证插件 - 比较两个选择下拉列表的自定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20469622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com