0

我是使用主干视图并尝试调试的新手。我有表单验证,当出现错误时填充新标签<ul><li>标签,如果我没有制作任何这些新元素,我只会将表单数据发送到后端。我需要检查他们。我发现这显示了我的输入字段设置为:

$('input').each(function(){console.log($(this).attr('id')+'  '+$(this).val());});

我读到了遍历 DOM

var listItems = $( 'ul' );
var special = listItems.filter( 'li' );

<ul> <li>这会在导航中找到第一组

我需要帮助扫描 DOM 以查找这些新标签,也许还有多个<ul> <li>标签,这些标签是我从 chrome 创建的带有错误的 HTML 提供的。谢谢!

<div class="nav-collapse collapse">
    <ul class="nav" id="navbutts">
        <li class="" id="homebutt"><a href="#">Home</a>
        </li>
        <li id="weddingbutt"><a href="#weddings">Weddings</a>
        </li>
        <li id="dancesbutt"><a href="#dances">Dances</a>
        </li>
        <li id="contactbutt"><a href="#contact">Contact</a>
        </li>
        <li id="registerbutt" class="active"><a href="#register">Register</a>
        </li>
        <li id="bookitbutt"><a href="#bookit">Book it</a>
        </li>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">More<b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="#owner">The Owner</a>
                </li>
                <li><a href="#equipment">Equipment</a>
                </li>
                <li><a href="#consulting">Event Consulting</a>
                </li>
                <li><a href="#testimonials">Testimonials</a>
                </li>
                <li><a href="#testimonialinks">Testimonials link</a>
                </li>
            </ul>
        </li>
    </ul>
</div>

<div class="control-group warning">
    <label class="control-label required" for="loginnameconf">Confirm Email</label>
    <div class="controls">
        <div class="input-prepend" data-role="acknowledge-input">
            <div data-role="acknowledgement" class="add-on" style="color: rgb(255, 0, 0);"><i class="icon-warning-sign"></i>
            </div>
            <input type="email" data-type="email" required="required" placeholder="Confirm email" maxlength="254" name="loginnameconf" id="loginnameconf" class="inputclass pageRequired input-xlarge" data-validation-match-match="loginname" data-validation-match-message="Emails must match"
            aria-invalid="true">
            <span class="loginnameconf_error label label-info hide"></span>
        </div>
        <div class="help-block">
            <ul role="alert">
                <li>Not a valid email address    // this was added to the DOM
                    <!-- data-validator-validemail-message to override -->
                </li>
                <li>Emails must match</li>    // this was added to the DOM
            </ul>
        </div>
    </div>
</div>

<div class="control-group warning">
    <label class="control-label required" for="password">Password</label>
    <div class="controls">
        <div class="input-prepend" data-role="acknowledge-input">
            <div data-role="acknowledgement" class="add-on" style="color: rgb(0, 255, 0);"><i class="icon-ok"></i>
            </div>
            <input type="password" required="required" placeholder="Password" minlength="6" maxlength="16" name="password" id="password" class="inputclass pageRequired input-medium" data-validation-minlength-message="6-16 characters required" data-validation-maxlength-message="6-16 characters required"
            aria-invalid="true">
        </div>
        <span class="password_error label label-info hide"></span>
        <div class="help-block">
            <ul role="alert">   // this was added to the DOM
                <li>6-16 characters required</li>
            </ul>
        </div>
    </div>  
</div>


// I can't seem to combine the filter and the .each to find the <ul><li> elements
   I added 

// shows names and values for form input text boxes
$('input').each(function(){console.log($(this).attr('id')+' '+$(this).val());}); 

var hasError = false; 

$('ul li').each(function(index){ 
    if( $(this).text().length !== 0 ){ 
        alert('Client side error found'); hasError = true; }
});
4

1 回答 1

0

我找不到这些验证库中的任何一个都设置了“验证成功”标志供我使用。因此,我需要确定是否存在新的

  • 标签

    I needed to scan for this:
    
         <div class="help-block">
            <ul role="alert">
                <li>Not a valid email address    // this was added to the DOM
    

    这样做

      $('div.help-block ul').each(function() {
         //alert('AHHHHHH!');
         hasError = true;
     }); // end each
    
     then later:
    
     if (hasError)
        { return false; }
      else
        {
        registermodel.save();
        return false;
            }
    
  • 于 2013-11-12T02:26:46.417 回答