Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在div'中的任意位置查找类;后代_Javascript_Jquery_Css_Forms_Twitter Bootstrap - Fatal编程技术网

Javascript 在div'中的任意位置查找类;后代

Javascript 在div'中的任意位置查找类;后代,javascript,jquery,css,forms,twitter-bootstrap,Javascript,Jquery,Css,Forms,Twitter Bootstrap,我有一个引导式手风琴/每个手风琴部分都有形式元素。当用户浏览不同的字段和accordion部分时,我希望根据他们是否填写了所有必需的数据显示一个范围。所有输入字段都位于部分中。如果用户未填写必填字段,则输入和标签周围的.form组将获取类。有错误。当他们解决问题时,.has error将替换为.no error 因此,如果.has error类出现在.section中的任何位置(所有后代包括孙辈),span.error字段应该出现在.lbl.lblBig中,它是紧靠.section之前的兄弟,并

我有一个引导式手风琴/每个手风琴部分都有形式元素。当用户浏览不同的字段和accordion部分时,我希望根据他们是否填写了所有必需的数据显示一个范围。所有输入字段都位于
部分
中。如果用户未填写必填字段,则输入和标签周围的
.form组
将获取类
。有错误
。当他们解决问题时,
.has error
将替换为
.no error

因此,如果
.has error
类出现在
.section
中的任何位置(所有后代包括孙辈),span
.error
字段应该出现在
.lbl.lblBig
中,它是紧靠
.section
之前的兄弟,并且包含该手风琴部分的标题。如果
.has error
在任何地方都看不到,那么我希望span
.ok
字段显示在
.lbl.lbig

$(".section").each(function(){
    if ($(this).find(".has-error").length) {
        $(this).prev(".lbl.lblBig").find(".field-error").show();
        $(this).prev(".lbl.lblBig").find(".field-ok").hide();
    }
    else if ($(this).find(".no-error").//do opposite of length? ) {
        $(this).prev(".lbl.lblBig").find(".field-error").hide();
        $(this).prev(".lbl.lblBig").find(".field-ok").show();
    }
});
以下是基本布局:

 <div class="lbl lblBig">
      Section 1
      <span class="field-error" style="display:none"></span>
      <span class="field-ok" style="display:none"></span>
 </div>
 <div class="section"> <!--input fields for section 1-->
      <div class="form-group">
           <label class="control-label">First</label>
           <input class="required form-control" placeholder="First">
      </div>
      <div class="form-group">
           <label class="control-label">Last</label>
           <input class="required form-control" placeholder="Last">
      </div>
 </div>
 <div class="lbl lblBig">
      Section 2
      <span class="field-error" style="display:none"></span>
      <span class="field-ok" style="display:none"></span>
 </div>
 <div class="section"> <!--input fields for section 2-->
      <div class="form-group">
           <label class="control-label">Street</label>
           <input class="required form-control" placeholder="Street">
      </div>
      <div class="form-group">
           <label class="control-label">City</label>
           <input class="required form-control" placeholder="City">
      </div>
 </div>

我无法更改任何页面和表单的HTML,因此我在这方面受到限制。任何帮助都将不胜感激。如果可以,我会给你烤一块饼干,但这是互联网,没有3D打印烘焙技术。谢谢。

您的条件表达式应该是
if(length>0)


您的条件表达式应该是
if(length>0)


您真的不能更改您提供的html中的任何内容吗?如果您在每个
中添加属性
required
,当单击submit按钮时,它将为您完成所有工作。我希望可以,但是不行。您真的不能更改您提供的html中的任何内容吗?如果您在每个
中添加属性
required
,则单击submit按钮时,该属性将为您完成所有工作。我希望可以,但不行。
$(".section").each(function(){
    if ($(this).find(".has-error").length > 0) {
        $(this).prev(".lbl.lblBig").find(".field-error").show();
        $(this).prev(".lbl.lblBig").find(".field-ok").hide();
    }
    else {
        $(this).prev(".lbl.lblBig").find(".field-error").hide();
        $(this).prev(".lbl.lblBig").find(".field-ok").show();
    }
});