我的问题与Targeting $(this) within nested for each loops in jQuery完全相同,但由于某种原因我无法使其发挥作用。这是我的代码:
$(document).ready(function() {
var rows=$('.row');
var count = 0;
$.each(rows, function() {
console.log(".row "+count++);
var row = $(this);
var cells = row.find('span.RIF_Field');
if (cells.length > 0) {
console.log("cells "+cells.length);
var hidden = true;
$.each(cells, function() {
if(!$(this).is(':hidden')) {
console.log($(this).id + " is visible");
hidden = false;
}
});
if (hidden) {
console.log("nothing is visible");
row.hide();
}
}
});
});

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div class="row"><div class="col-sm-6"><br style="clear:both;">
<div class="RIF_Field RIF_Street" id="yourStreet" style="float:left;width:200px;"><label class="fldLbl" id="yourStreetLabel">Address Line 1:</label><br>
<span style="white-space: nowrap;"><input id="yourStreetValue" maxlength="35" name="yourStreet" size="32" style="width:200px;" type="text"><img alt="" height="9" id="yourStreetReqdImg" src="/img/1.gif" width="11"></span></div>
</div>
<div class="col-sm-6"><br style="clear:both;">
<div class="RIF_Field RIF_Addr2" id="yourAddr2" style="float:left;width:200px;"><label class="fldLbl" id="yourAddr2Label">Address Line 2:</label><br>
<span style="white-space: nowrap;"><input id="yourAddr2Value" maxlength="35" name="yourAddr2" size="32" style="width:200px;" type="text"><img alt="" height="9" id="yourAddr2ReqdImg" src="/img/1.gif" width="11"></span><br>
<span class="RIF_description">Test</span></div>
</div>
</div>
<div class="row"><div class="col-sm-6"><br style="clear:both;">
<div class="RIF_Csp3" id="yourCsp3" style="float:left;"><span class="RIF_Field RIF_State" id="yourState" style="display: none;"><label class="fldLbl" id="yourStateLabel">Other Address Information:</label><br>
<span style="white-space: nowrap;"><input type="text" size="15" maxlength="15" id="yourStateValue" name="yourState" onchange="null" onfocus="null" onblur="null" tabindex="0" class="ui-autocomplete-input" autocomplete="off"><img alt="" height="9" id="yourStateReqdImg" src="/img/1.gif" width="11"></span></span></div>
</div>
<div class="col-sm-6"><div></div>
</div>
</div>
<div class="row"><div class="col-sm-6"><br style="clear:both;">
<div class="RIF_Field RIF_Phone" id="yourPhone" style="float:left;width:300px;"><label class="fldLbl" id="yourPhoneLabel">Telephone:</label><br>
<span style="white-space: nowrap;"><input id="yourPhoneValue" maxlength="15" name="yourPhone" size="15" style="width:300px;" type="text"><img alt="" height="9" id="yourPhoneReqdImg" src="/img/1.gif" width="11"></span></div>
<div class="RIF_Field RIF_Extension" id="yourExtension" style="float:left;width:100px;"><label class="fldLbl" id="yourExtensionLabel">Ext.:</label><br>
<span style="white-space: nowrap;"><input id="yourExtensionValue" maxlength="5" name="yourExtension" size="5" style="width:100px;" type="text"><img alt="" height="9" id="yourExtensionReqdImg" src="/img/1.gif" width="11"></span></div>
</div>
<div class="col-sm-6"><br style="clear:both;">
<div class="RIF_Field RIF_Email" id="yourEmail" style="float:left;width:400px;"><label class="fldLbl" id="yourEmailLabel">E-mail:</label><br>
<span style="white-space: nowrap;"><input id="yourEmailValue" maxlength="50" name="yourEmail" size="32" style="width:400px;" type="text"><img alt="" height="9" id="yourEmailReqdImg" src="/img/1.gif" width="11"></span></div>
</div>
</div>
</div>
&#13;
我试图隐藏隐藏所有单元格的.row元素。我做错了什么?
答案 0 :(得分:0)
代码File origional = new File(fileorig);
无效您想cells.size()
。它也永远不会为空。
cells.length
&#13;
$(document).ready(function() {
var rows=$('.row');
var count = 0;
$.each(rows, function() {
console.log(".row "+count++);
var row = $(this);
var cells = row.find('span.RIF_Field');
if (cells.length > 0) {
console.log("cells "+cells.length);
var hidden = true;
$.each(cells, function() {
if(!$(this).is(':hidden'))
console.log($(this).id + " is visible");
hidden = false;
});
if (hidden) {
console.log("nothing is visible");
row.hide();
}
}
});
});
&#13;