简体   繁体   English

仅选择Html.dropdownlist之外的最近输入

[英]Selecting only the closest input outside of a Html.dropdownlistfor

I have three dropdownlistfor sets, with three separate inputs that are shown on selecting the value "other" from the list. 我有三个dropdownlistfor集,其中包含三个单独的输入,这些输入在从列表中选择值“ other”时显示。 The following code is meant to select only the closest input to the item that was clicked. 以下代码仅用于选择与单击的项目最接近的输入。

    Set 1
              @Html.DropDownListFor(m => m.Title, "--Select Title --", new { @class = "form-control requiredField dropListFunction", required="true" })

    set2
                @Html.TextBoxFor(m => m.TitleOther, new { @class = "form-control hidden", placeholder = "Enter New Title" }) 

              @Html.DropDownListFor(m => m.Branch "--Select Branch --", new { @class = "form-control requiredField dropListFunction", required = "true" })

         @Html.TextBoxFor(m => m.BranchOther, new { @class = "form-control hidden", placeholder = "Enter New Branch" })  

Set 3   
        @Html.DropDownListFor(m => m.State, Enum.GetNames(typeof(State)).Select(e => new SelectListItem { Text = e }), "--Select State --", new { @class = "form-control requiredField dropListFunction", required = "true" })

 @Html.TextBoxFor(m => m.StateOther, new { @class = "form-control hidden", placeholder = "Enter New State" })

with the following jquery handling selection of the input closest to the dropListFunction that contains a clicked option with value other 以下jquery处理最接近dropListFunction的输入的选择,其中包含具有其他值的clicked选项

   $('option[value=Other]').on('click',function(){
            var nextInput = $('.dropListFunction').next('input');
            nextInput.removeClass('hidden')
        });

The problem is that it is not selecting just the next item in the list, but opening all hidden inputs when selected. 问题在于它不只是选择列表中的下一个项目,而是在选择时打开所有隐藏的输入。 Any help is greatly appreciated 任何帮助是极大的赞赏

All your DropDowns have the class .dropListFunction so you will get all the next inputs. 您所有的DropDown都具有.dropListFunction类,因此您将获得所有后续输入。

$('.dropListFunction').on('change', function(e){
    var dd = $(e.target), input = dd.next('input');
    if(dd.val() === 'other'){
      input.removeClass('hidden');
    }else{
      input.addClass('hidden');
    }
  });

see jsbin here 在这里看到jsbin

https://jsbin.com/lacimoyula/edit?html,console,output https://jsbin.com/lacimoyula/edit?html,控制台,输出

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM