0
我在這裏有一個問題。jquery道具所需的錯誤
支柱功能: 所以我有一個問題,將兩個選項設置爲required。一個工作,一個不工作。 .prop('required',true);
適用於#additional_here_about_other_field
。這將該字段設置爲必需。但.prop('required',true);
不適用於#additional_who_is_your_orthodontist_field
。我想要這個字段也是必需的,但它不起作用。
jQuery(document).ready(function() {
\t
\t if(jQuery("#additional_here_about_other_field").length > 0){
\t \t jQuery("#additional_here_about_other_field").hide();
\t \t jQuery("#additional_how_did_u_hear_about_harp").change(function(){
\t \t \t if(jQuery(this).val() == 'Other (please specify)'){ jQuery("#additional_here_about_other_field").show().prop('required',true); }
\t \t \t else { jQuery("#additional_here_about_other_field").hide(); }
\t \t });
\t }
\t if(jQuery("#additional_who_is_your_orthodontist_field").length > 0){
\t \t jQuery("#additional_who_is_your_orthodontist_field").hide();
\t \t jQuery("#additional_how_did_u_hear_about_harp").change(function(){
\t \t \t if(jQuery(this).val() == 'Orthodontist Referral'){ jQuery("#additional_who_is_your_orthodontist_field").show().prop('required',true); }
\t \t \t else { jQuery("#additional_who_is_your_orthodontist_field").hide(); }
\t \t });
\t }
});
HTML snippet
<select name="additional_how_did_u_hear_about_harp" id="additional_how_did_u_hear_about_harp" class="select " data-allow_clear="true" data-placeholder="How Did You Hear About The Harp?" >
\t <option value="" selected='selected'></option>
\t <option value="Patient" >Patient</option>
\t <option value="Orthodontist Referral" >Orthodontist Referral</option>
\t <option value="Trade Show" >Trade Show</option>
\t <option value="Mailer" >Mailer</option>
\t <option value="Other (please specify)" >Other (please specify)</option>
</select>
<div class="clear"></div>
<p> \t \t
\t <input type="text" class="input-text " name="additional_here_about_other_field" id="additional_here_about_other_field" placeholder="Other (please specify)" value="" />
</p>
<div class="clear"></div>
<p> \t \t
\t <input type="text" class="input-text " name="additional_who_is_your_orthodontist" id="additional_who_is_your_orthodontist" placeholder="Who is your orthodontist?" value="" />
</p>
<div class="clear"></div>
請添加HTML代碼到您的片段 –
@CarstenLøvboAndersen添加HTML代碼段 –
請張貼在不同的問題,不同的問題 – abl