我有兩個具有相同類名的表單。我想檢查點擊的所有必填字段。 HTML:每個這個對象內使用jquery
<form action="#" id="form_sample_3" class="form-horizontal normalForm1">
<div class="form-group c_name_container">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-envelope"></i>
</span>
<input type="text" id="c_name" class="required" placeholder="Type your Name here"/>
</div>
</div>
</div>
<div class="form-group c_email_container">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-envelope"></i>
</span>
<input type="email" id="c_email" class="required" placeholder="Type your Email Address">
</div>
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-9">
<button type="button" id="start_chat" class="btn green">Start Chat</button>
</div>
</div>
</div>
</form>
現在,
$(document).on("click", ".normalForm button[type='submit']", function() {
// this will refer clicked form having class `normalForm`
// Here i want to looping for all .required class.
$('.required').each(function(){
// it works fine. but it looping also others .required class of other form in same page. How can I looping only inside my clicked form?
});
});
'$( '#form_sample_3 .required')每個(函數(){...' – ojovirtual
@ojovirtual ** **沒有!!!!他希望它在_current_表格上參數化,而不是硬編碼的! – Alnitak