我有多个div和子字段。这些子字段共享相似的名称。我正在尝试显示特定的子字段。但是我只得到第一分区的子字段。它与子级Field的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();
});
最佳答案
尝试这个:
var childFieldDivId = '#parent-'+fieldName;
$(childFieldDivId).find('div').each(function(index, value){
$(this).show();
});
fiddle
关于javascript - 选择div的子字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18495468/