0
Follow
0
View

requierd problems for select triggered by javascript

dian19920226 注册会员
2023-02-27 15:41
Hello, I am asked to answer the little assistant, your question has been a little partner to help you answer, thank you for your support and attention to have asked to answer!
PS: Q&A VIP annual card [limited time plus: free IT technical books], for details > > > https://vip.csdn.net/askvip?utm_source=1146287632
ddpaopaovip 注册会员
2023-02-27 15:41

You can use logical operators(e.g. & & And | |) to do this. You can create a variable(such as allCatSelected) that stores whether the non-empty option is selected for both cat1 and cat2. If so, you can set the required attribute for cow1 and cow2 to false to disable their validation. You can also use this logic to validate all fields at form submission time. This code can be placed in the appropriate place in the form_check function as needed. A code example is as follows:


```c++
var allCatSelected = ($('#cat1').val() !== '') && ($('#cat2').val() !== '');

if (allCatSelected) {
    $('#cow1').prop('required', false);
    $('#cow2').prop('required', false);
} else {
    $('#cow1').prop('required', true);
    $('#cow2').prop('required', true);
}




cwhjh_1 注册会员
2023-02-27 15:41
value != '' && cat2.value != '') {//都不为空再执行验证,同时加上required property $('#cow1,#cow2').prop('required',true) valid1.cow1(); valid1.cow2(); } else {//移除required property $('#cow1,#cow2').prop('required', false) } return !v.has_errors(); }; .
< !- - - - - >

About the Author

Question Info

Publish Time
2023-02-27 15:41
Update Time
2023-02-27 15:41