【发布时间】:2011-07-10 12:18:10
【问题描述】:
好的,我有一个带有一些问题的表单作为单选选项。如果第一个单选被选为选项是,则显示第二个单选选项。如果还选择了第二个单选选项是作为选项,则显示第三个元素(文本框)。
此功能正在运行,但我无法使用的是,如果他们将第一个单选选项更改为 no,我如何隐藏和取消设置第二个单选选项(将选项设置为 no)并清除和隐藏第三个元素(文本框)值。
这是我尝试过的:
$("#second_radio_div").hide("fast");
$("#third_element_div").hide("fast");
$("[name=first_radio]").change(function(){
$("#second_radio_div").toggle($("[name=first_radio]").index(this)===1);
if($("[name=first_radio]").index(this)===0) {
//$('input:radio[name="second_radio_no"]').attr('checked',true);
//$('#second_radio').buttonset("refresh");
//$('[name="second_radio"][value="no"]').attr("checked", true);
//$('#second_radio').buttonset("refresh");
$("#third_element_div").hide("fast"); // This works to hide the element
}
});
$("[name=second_radio]").change(function(){
$("#third_element_div").toggle($("[name=second_radio]").index(this)===1);
});
HTML
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<div>First Radio</div>
<input type="radio" name="first_radio" id="first_radio_yes" value="yes" />
<label for="first_radio_yes">Yes</label>
<input type="radio" name="first_radio" id="first_radio_no" value="no" checked="checked"/>
<label for="first_radio_no">No</label>
</fieldset>
</div>
<div id="second_radio_div" name="second_radio_div">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<div>Second Radio</div>
<input type="radio" name="second_radio" id="second_radio_yes" value="yes" />
<label for="second_radio_yes">Yes</label>
<input type="radio" name="second_radio" id="second_radio_no" value="no" checked="checked"/>
<label for="second_radio_no">No</label>
</fieldset>
</div>
</div>
<div id="third_element_div" name="third_element_div">
<div data-role="fieldcontain">
<input type="text" name="third_element" id="third_element" class="default-value" value="If yes, provide date" />
</div>
</div>
【问题讨论】:
标签: jquery jquery-ui radio-button toggle jquery-mobile