JQuery:查找父级和另一个子级
我有以下标记:JQuery:查找父级和另一个子级,jquery,Jquery,我有以下标记: <div style="width: 660px; border-bottom: 1px solid #3A3F46;"> <div class="noplace_event_cont"> <div style="float: left;"> <span class="title">Usual</span>
<div style="width: 660px; border-bottom: 1px solid #3A3F46;">
<div class="noplace_event_cont">
<div style="float: left;">
<span class="title">Usual</span>
<span class="desc">Free: <span class="free_place">19</span></span>
</div>
<div style="float: right;">
<div class="spinner_cont">
<input type="text" data-type="1" class="event_spinner" value="0" maxlength="1" style="width: 24px; margin-right: 16px; text-align: right;"><span class="ui-spinner ui-widget"><div class="ui-spinner-buttons" style="height: 41px; left: -16px; top: -13.0833px; width: 36px;"><div class="ui-spinner-up ui-spinner-button ui-state-default ui-corner-tr" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-n" style="margin-left: 16.5px; margin-top: 15px;"> </span></div><div class="ui-spinner-down ui-spinner-button ui-state-default ui-corner-br" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-s" style="margin-left: 16.5px; margin-top: 15px;"> </span></div></div></span>
</div>
</div>
</div>
<div class="noplace_event_cont">
<div style="float: left;">
<span class="title">VIP</span>
<span class="desc">Free: <span class="free_place">6</span></span>
</div>
<div style="float: right;">
<div class="spinner_cont">
<input type="text" data-type="2" class="event_spinner" value="0" maxlength="1" style="width: 24px; margin-right: 16px; text-align: right;"><span class="ui-spinner ui-widget"><div class="ui-spinner-buttons" style="height: 41px; left: -16px; top: -13.0833px; width: 36px;"><div class="ui-spinner-up ui-spinner-button ui-state-default ui-corner-tr" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-n" style="margin-left: 16.5px; margin-top: 15px;"> </span></div><div class="ui-spinner-down ui-spinner-button ui-state-default ui-corner-br" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-s" style="margin-left: 16.5px; margin-top: 15px;"> </span></div></div></span>
</div>
</div>
</div>
</div>
但是,这个代码不起作用<代码>最大值未定义。谢谢 或 或 我想在“自由位置”类的span中查找文本: 或者这个:
$('span.free_place').text()
很难理解您希望输出是什么
我想在“自由位置”类的span中查找文本:
或者这个:
$('span.free_place').text()
很难理解您希望输出是什么。使用.closest()
使用.closest()
你应该写下你想要的输出是什么,你想做什么,为什么。你应该写下你想要的输出是什么,你想做什么,为什么。不要使用
父母,也许他需要最接近的,但问题很不明确不要使用父母,也许他需要最接近的,但问题很不清楚
var max = $(this).closest(".noplace_event_cont").find(".free_place").text();
var max = $(this).closest(".free_place").text();
$('span .free_place').text()
$('span.free_place').text()
$(".event_spinner").each(function () {
var max = $(this).closest(".noplace_event_cont").find(".free_place").text();
alert(max);
});