简体   繁体   English

基于另一个下拉值的活动或非活动下拉列表

[英]active or disactive dropdown list based on another dropdown value

hi i have 3 drop down list in my contact form which i active or disactive two of them with first drop down list. 嗨,我在联系表格中有3个下拉列表,我使用第一个下拉列表激活或不激活其中两个。 till today my first drop down had two options and when i selected rent,it made price range disactive automatically and when i selected sell,it made rent range drop down disactive automatically. 直到今天,我的第一个下拉菜单有两个选项,当我选择租金时,它会自动使价格范围无效;当我选择出售时,它会使租金范围的下拉条件自动无效。 today i decided to add one more option to first drop down "presell" now i want to disactive rent range and active price range when i select this option too exactly like sell option. 今天,我决定添加一个选项来首先下拉“预售”,现在我想取消激活租金范围和激活价格范围,因为我选择的选项太像卖出选项了。 but i can not mange it. 但我不能ge。 please help me? 请帮我? thank you 谢谢

 <html> <body> <p dir="rtl"><select id="select" name="case" style="width: 110px;"> <option selected="selected" value="red">sell</option> <option value="green">rent</option> <option value="blue">presell</option> </select></p> <p dir="rtl"><select name="pricerange" class="myclass1" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="1" >A</option> <option value="2" >B</option> <option value="3" >C</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ $('.myclass1').attr('disabled',$(this).val() === 'green'); }); </script> <p dir="rtl"><select name="rentrange" class="myclass2" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="4" >AA</option> <option value="5" >BB</option> <option value="6" >CC</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ $('.myclass2').attr('disabled',$(this).val() === 'red'); }); </script> </body> </html> 

You just need to check if the value of the #select dropdown is or red or blue. 你只需要检查的值#select下拉菜单是红色蓝色。 using this code: 使用此代码:

var val = $(this).val();
$('.myclass2').attr('disabled',val === 'red' || val == 'blue');

 <html> <body> <p dir="rtl"><select id="select" name="case" style="width: 110px;"> <option selected="selected" value="red">sell</option> <option value="green">rent</option> <option value="blue">presell</option> </select></p> <p dir="rtl"><select name="pricerange" class="myclass1" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="1" >A</option> <option value="2" >B</option> <option value="3" >C</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ $('.myclass1').attr('disabled',$(this).val() === 'green'); }); </script> <p dir="rtl"><select name="rentrange" class="myclass2" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="4" >AA</option> <option value="5" >BB</option> <option value="6" >CC</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ var val = $(this).val(); $('.myclass2').attr('disabled',val === 'red' || val == 'blue'); }); </script> </body> </html> 

Use the jquery in array function 在数组函数中使用jQuery

$('.myclass2').attr('disabled', $.inArray(val, ['blue','red'])); $('。myclass2')。attr('disabled',$ .inArray(val,['blue','red'])));

 <html> <head> <head> <body> <p dir="rtl"> <select id="select" name="case" style="width: 110px;"> <option selected="selected" value="red">sell</option> <option value="green">rent</option> <option value="blue">presell</option> </select> </p> <p dir="rtl"> <select name="pricerange" class="myclass1" style="width: 110px;" disabled="disabled"> <option value="">please select</option> <option value="1">A</option> <option value="2">B</option> <option value="3">C</option> </select> </p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function() { $('.myclass1').attr('disabled', $(this).val() === 'green'); }); </script> <p dir="rtl"> <select name="rentrange" class="myclass2" style="width: 110px;" disabled="disabled"> <option value="">please select</option> <option value="4">AA</option> <option value="5">BB</option> <option value="6">CC</option> </select> </p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function() { var val = $(this).val(); $('.myclass2').attr('disabled', $.inArray(val, ['blue','red'])); }); </script> </body> </html> 

Add another equation with 'or' operater (||) to the attribute condition. 将带有“或”运算符(||)的另一个方程式添加到属性条件。

 <html> <head> <head> <body> <p dir="rtl"><select id="select" name="case" style="width: 110px;"> <option selected="selected" value="red">sell</option> <option value="green">rent</option> <option value="blue">presell</option> </select></p> <p dir="rtl"><select name="pricerange" class="myclass1" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="1" >A</option> <option value="2" >B</option> <option value="3" >C</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ $('.myclass1').attr('disabled',$(this).val() === 'green'); }); </script> <p dir="rtl"><select name="rentrange" class="myclass2" style="width: 110px;" disabled="disabled"> <option value="" >please select</option> <option value="4" >AA</option> <option value="5" >BB</option> <option value="6" >CC</option> </select></p> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> <script> $('#select').change(function(){ $('.myclass2').attr('disabled', $(this).val() === 'red' || $(this).val() === 'blue' ); }); </script> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据另一个下拉列表填充一个下拉列表,并获取“值”,而不是显示值的下拉列表 - Populate one dropdown list based on another dropdown list and get “value” instead of dropdown showing value 根据另一个下拉列表中的选择填充下拉列表 - Populate dropdown list based on selection in another dropdown 根据在另一个下拉列表中选择的值填充下拉列表 - Populating a dropdown based on the value selected in another dropdown 根据另一个下拉列表更改下拉选择值? - Change dropdown selection value based on another dropdown? 根据另一个下拉列表选择一个下拉列表的值 - select value of one dropdown based on another dropdown 根据另一个下拉值获取下拉数据 - Get data on dropdown based on another dropdown value 基于另一个下拉列表的动态文本框和下拉列表-javascript - Dynamic textbox and dropdown list based on another dropdown list -javascript 根据同一 html 表单中的另一个下拉列表填充下拉列表 - Filling a dropdown list based on another dropdown list in the same html form 如何基于另一个下拉列表启用和禁用下拉列表项 - How to enable and disable dropdown list items based on another dropdown list 根据另一个下拉列表动态更新下拉列表? - Dynamically update a dropdown list based on another dropdown list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM