使用另一个单选选择和刷新按钮而不是页面切换单选选择
好的,我有一个表格,其中包含一些问题作为单选选项。如果第一个单选选项被选为 yes,则显示第二个单选选项。如果第二个单选选项也选择“是”作为选项,则显示第三个元素(文本框)。
此功能正在工作,但我无法工作的是,如果他们将第一个单选选项更改为“否”,我如何隐藏并取消设置第二个单选选项(将选项设置为“否”)并清除并隐藏第三个元素(文本框)价值。
这是我尝试过的:
$("#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>
Ok I Have a form with some questions as a radio option. If the first radio is selected as option yes, display the second radio option. if second radio option is also selected yes as the option, display third element (text box).
This functionality is working but what I can't get to work is if they change the first radio selection to no how can I hide and unset the second radio option (set option to no) and clear and hide the third element (text box) value.
Here is what I have tried:
$("#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);
});
The 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
工作示例: http://jsfiddle.net/hunter/N6qmr/
我认为主要问题是什么你有这一行:
应该是:
因为没有
[name="second_radio_no"]
元素working example: http://jsfiddle.net/hunter/N6qmr/
I think the main problem with what you had was this line:
Should have been:
Since there is no element with
[name="second_radio_no"]
怎么样:
在这里工作: http://jsfiddle.net/dVAzj/2/
请注意,引号是属性等于中的“值”周围需要 (
[name=' value']
) 选择器。How about:
Working here: http://jsfiddle.net/dVAzj/2/
Note that quotes are required around the 'value' in the attribute equals (
[name='value']
) selector.