我目前正在使用此代码根据用户选择的内容显示和消失输入框
<label class="title">Is the Primary Contact a Director of the corporation?</label>
<input type="radio"{if freeform:mp_data:type=="Yes"} checked="checked"{/if} name="type" id="primary_contact_director_1" value="Yes"> Yes</input><br>
<input type="radio"{if freeform:mp_data:type=="No"} checked="checked"{/if} name="type" id="primary_contact_director_2" value="No"> No</input><br><br>
<div id="Yes_box">
</div>
<div id="No_box">
<label class="title">Director's First Name:</label>
<input type="text" name="director_first_name" class="form" value="{freeform:mp_data:director_first_name}">
<label class="title">Director's Last Name:</label>
<input type="text" name="director_last_name" class="form" value="{freeform:mp_data:director_last_name}">
<label class="title">Address:</label>
<input type="text" name="director_address" class="form" value="{freeform:mp_data:director_address}">
<label class="title">City:</label>
<input type="text" name="director_city" class="form" value="{freeform:mp_data:director_city}">
<label class="title">State:</label>
<input type="text" name="director_state" class="form" value="{freeform:mp_data:director_state}">
<label class="title">Zip Code</label>
<input type="text" name="director_zip_code" class="form" value="{freeform:mp_data:director_zip_code}">
</div>
<script>
$(document).ready(function(){
var myRadio = $('input[name=type]');
var checkedValue = myRadio.filter(':checked').val();
if(checkedValue=='No'){
$('#No_box').show();
}else{
$('#No_box').hide();
}
$('#Yes_box_two').hide();
});
</script>
但我需要名称字段才能显示结果,所以我想更改输入[name = type]以调用id而不是名称
答案 0 :(得分:0)
所以改变
var myRadio = $('input[name=type]');
到
var myRadio = $('input[id=type]');
或
var myRadio = $('input#type');
答案 1 :(得分:0)
我觉得你很困惑,你的行如下:
var myRadio = $('input[name=type]');
应该真的像这样才有意义:
var myRadio = $('input[type=radio]');