简体   繁体   English

当选择另一个框时,从选择框中删除“禁用”属性

[英]Remove 'disable' property from select box when another box is selected

I have two select boxes where user can choose category and subcategory. 我有两个选择框,用户可以在其中选择类别和子类别。 I want to subcategory be disabled by default and enabled when user has previously selected the category. 我希望子类别在默认情况下处于禁用状态,并在用户先前选择类别时启用。

<select name="cat" onclick="this.form.submit()" style="width:220px;height:120px;" size="8">
    <option value="">All categories</option>
        @foreach($categoriesFilter as $cf)
            <option value="{{ $cf->mainCat_de }}">{{ $cf->mainCat_de }}</option>
        @endforeach
</select>

and

<select name="subcat" id="subcat" onchange="this.form.submit()" style="width:220px;height:120px;" size="8" disabled>
    <option value="">All subcategories</option>
        @foreach($subCategoriesFilter as $sf)
            <option value="{{ $sf->cat_de }}">{{ $sf->cat_de }}</option>
        @endforeach
</select>

I tried to do this, but it's not working: 我试图这样做,但是不起作用:

<script type="text/javascript">
    var cat = {{ Request::get('cat') }};

    if( cat != "" || cat != null ){
        $('#subcat').prop('disabled', false);
    }
</script>

If you wish to use Variable from Laravel's Blade that is a string, it must be wrapped in quotes. 如果您希望使用Laravel的Blade中的Variable(字符串),则必须将其用引号引起来。

What your code could equate to is var cat = fruits , which will throw a syntax error. 您的代码可能等同于var cat = fruits ,这将引发语法错误。 By wrapping the blade in quotes, you're correctly saying var cat = "fruits" . 通过将刀片用引号引起来,您可以正确地说var cat = "fruits"

var cat = "{{ Request::get('cat') }}";

$('#subcat').prop('disabled', cat == "" || cat == null);

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

相关问题 在另一个选择框中选择时,从一个选择框中禁用选择的选项 - Disable selected option from one select box when selected in another select box 从另一个选择框中删除选定的选项 - Remove selected option from another select box 禁用 <select>在另一个选择时选项<select>框 - Disable <select> option when selected in another <select> box 从另一个多选2框中删除所选项目时,从多个select2框中删除所选项目 - Remove a selected item from multiple select2 box on removal of selected item from another multiple select 2 box 当使用jQuery在同一行中选择另一个选择框时,如何禁用另一个选择框 - how to disable in another select box when the other selection box is selected in the same row using jquery 选择其他项目时,在选择框中添加和删除选项 - add and remove options from select box when other item selected 从选择框中删除选择的选项 - Remove the selected option from select box 隐藏其他选择框中的选定选项 - Hide selected option from another select box 禁用已在另一个多选框中选择的选项 - Disable options already selected in another multiple select box 使用jQuery从选择框中删除选择的值,但需要在选择框中显示当前选择的值吗? - remove selected value from select box using jquery but It's need to display current selected value in select box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM