我有一个下拉列表,通过更改它, 某些包含文本框和选择框的div隐藏 而其中只有一个正在显示。 如何通过serialize()获得divs haven`t类“隐藏”中的唯一输入?
<div class="row">
<div id="student-section-2" class="hide">
<div class="col-sm-6 col-md-3">
<label class="control-label" for="">bases</label>
<input id="base-2" class="form-control bases" alt="2" type="text">
</div>
<div class="col-sm-6 col-md-2">
<label class="control-label" for="">fields</label>
<input id="field-2" class="form-control fields" alt="2" type="text">
</div>
<div class="col-sm-6 col-md-3">
<label class="control-label" for="">students</label>
<input id="student-2" class="form-control students" alt="2" type="text">
</div>
</div>
<div id="bank-section-2" class="hide">
<div class="col-sm-6 col-md-3">
<label class="control-label" for="">accounts</label>
<select id="financial-account-type-2" class="form-control finan-acc-types" name="financial-account-type" alt="2">
<option value="">select</option>
<option value="1">s</option>
<option value="2">b</option>
<option value="3">p</option>
<option value="4">a</option>
<option value="5">h</option>
</select>
</div>
</div>
<div id="personal-section-2" class="">
<div class="col-sm-6 col-md-3">
<label class="control-label" for="">s</label>
<input id="s-2" class="form-control s" alt="2" type="text">
</div>
<div class="col-xs-12">
<label class="control-label" for="">notes</label>
<textarea id="note-2" class="form-control notes" alt="2"></textarea>
</div>
</div>
</div>
例如,我想获得 personal-section-2 输入! 坦克给你答案;)
答案 0 :(得分:0)
您可以对要获取的div做两个类。
<div id="student-section-2" class="test hide">
然后拆分各类,并检查其是否具有隐藏的第二类。
$("#dropdownchange").change(function(){
$("#btn").click(function(){
$( ".test" ).each(function( ) {
if($( this ).attr('class').split(' ')[1] =='hide')
{
alert("i am hide do nothing");
}
else
{
alert("i am not hidden");
//here you can get your input
var el = $(this).find("input");
alert(el.val());
//for looping through multiple links you can see the follwoing question
}
});
检查该问题。.How to get all child inputs of a div element (jQuery) of-a-div-element-jquery