我是使用主干视图并尝试调试的新手。我有表单验证,当出现错误时填充新标签<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; }
});