-3

我目前正在使用此代码使输入框出现和消失,具体取决于我的用户选择的内容

<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>

但是,我需要名称字段才能显示结果,所以我想更改 input[name=type] 以调用 id 而不是名称

4

2 回答 2

0

所以改变

var myRadio = $('input[name=type]');

var myRadio = $('input[id=type]');

或者

var myRadio = $('input#type');
于 2012-12-07T17:14:28.527 回答
0

我认为您很困惑,您的以下行:

var myRadio = $('input[name=type]');

应该真的是这样才有意义:

var myRadio = $('input[type=radio]');
于 2012-12-07T17:14:48.000 回答