我有多个带有子字段的 div。这些子字段共享相似的名称。我正在尝试显示特定的子字段。但我只得到第一个 div 的子字段。
它与子字段的name
HTML有什么关系吗
<div class="row childFields" id="parent-question1">
<p class="subtitle">Give full details here: </p>
<div class="col-md-6 colChildFields" style="display:none" name="condition">
<label class="pocLabel">Nature of Condition</label>
<input type="text" name="condition" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="datesAndDuration">
<label class="pocLabel">Dates and Duration</label>
<input type="text" name="datesAndDuration" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="doctorName">
<label class="pocLabel">Name Of Doctor</label>
<input type="text" name="doctorName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalName">
<label class="pocLabel">Name of Hospital</label>
<input type="text" name="hospitalName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalAddress">
<label class="pocLabel">Address of Hospital</label>
<input type="text" name="hospitalAddress" class="form-control">
</div>
</div>
<div class="row childFields" id="parent-question2">
<p class="subtitle">Give full details here: </p>
<div class="col-md-6 colChildFields" style="display:none" name="condition">
<label class="pocLabel">Nature of Condition</label>
<input type="text" name="condition" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="datesAndDuration">
<label class="pocLabel">Dates and Duration</label>
<input type="text" name="datesAndDuration" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="doctorName">
<label class="pocLabel">Name Of Doctor</label>
<input type="text" name="doctorName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalName">
<label class="pocLabel">Name of Hospital</label>
<input type="text" name="hospitalName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalAddress">
<label class="pocLabel">Address of Hospital</label>
<input type="text" name="hospitalAddress" class="form-control">
</div>
</div>
<div class="row childFields" id="parent-question3">
<p class="subtitle">Give full details here: </p>
<div class="col-md-6 colChildFields" style="display:none" name="condition">
<label class="pocLabel">Nature of Condition</label>
<input type="text" name="condition" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="datesAndDuration">
<label class="pocLabel">Dates and Duration</label>
<input type="text" name="datesAndDuration" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="doctorName">
<label class="pocLabel">Name Of Doctor</label>
<input type="text" name="doctorName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalName">
<label class="pocLabel">Name of Hospital</label>
<input type="text" name="hospitalName" class="form-control">
</div>
<div class="col-md-6 colChildFields" style="display:none" name="hospitalAddress">
<label class="pocLabel">Address of Hospital</label>
<input type="text" name="hospitalAddress" class="form-control">
</div>
</div>
jQuery
var childFieldDivId = '#parent-'+fieldName;
$(childFieldDivId).find('div').each(function(i, childField){
$(childField).show();
});