【问题标题】:how to get elements in unhide div by serialize method如何通过序列化方法获取取消隐藏div中的元素
【发布时间】:2018-12-23 07:19:51
【问题描述】:

我有一个下拉菜单,通过更改它, 一些包含文本框和选择框的 div 被隐藏 并且只有其中一个正在显示。 如何通过 serialize() 获取 div 中没有类“隐藏”的唯一输入?

<div class="row">
    <div id="student-section-2" class="hide">
            <div class="col-sm-6 col-md-3">
                <label class="control-label" for="">bases</label>
                <input id="base-2" class="form-control  bases"  alt="2" type="text">
            </div>
            <div class="col-sm-6 col-md-2">
                <label class="control-label" for="">fields</label>
                <input id="field-2" class="form-control  fields"  alt="2" type="text">
            </div>
            <div class="col-sm-6 col-md-3">
                <label class="control-label" for="">students</label>
                <input id="student-2" class="form-control  students"  alt="2" type="text">                                  
            </div>

    </div>
    <div id="bank-section-2" class="hide">
            <div class="col-sm-6 col-md-3">
                <label class="control-label" for="">accounts</label>
                <select id="financial-account-type-2" class="form-control  finan-acc-types" name="financial-account-type" alt="2">
                    <option value="">select</option>
                    <option value="1">s</option>
                    <option value="2">b</option>
                    <option value="3">p</option>
                    <option value="4">a</option>
                    <option value="5">h</option>
                </select>

            </div>
    </div>
    <div id="personal-section-2" class="">
            <div class="col-sm-6 col-md-3">
                <label class="control-label" for="">s</label>
                <input id="s-2" class="form-control  s"  alt="2" type="text">                                   
            </div>
            <div class="col-xs-12">
                <label class="control-label" for="">notes</label>
                <textarea id="note-2" class="form-control notes"  alt="2"></textarea>                           
            </div>
    </div>
</div>

例如,我想获得 personal-section-2 输入! 坦克你的答案;)

【问题讨论】:

    标签: jquery


    【解决方案1】:

    你可以对你想要得到的 div 做两个类。

             <div id="student-section-2" class="test hide">
    

    然后拆分类并检查它是否具有隐藏的第二类。

        $("#dropdownchange").change(function(){
    
            $("#btn").click(function(){
            $( ".test" ).each(function( ) {
          if($( this ).attr('class').split(' ')[1] =='hide')
              {
               alert("i am hide do nothing");
               }
          else
             {
             alert("i am not hidden");
               //here you can get your input 
              var el = $(this).find("input");
               alert(el.val());
              //for looping through multiple links you can see the follwoing question
              }
    
    
    });
    

    检查这个问题..How to get all child inputs of a div element (jQuery)of-a-div-element-jquery

    【讨论】:

    • 感谢您的回复阿里。但我想在没有 hide 类名的情况下在每个 div 中获取输入,而不是显示或隐藏它们。而且更重要的是,它们的数量比这个高得多,我不想用 if 和 else 得到它们。
    猜你喜欢
    • 1970-01-01
    • 2022-11-15
    • 2012-12-15
    • 2019-01-25
    • 2013-08-10
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多