我有2个单选按钮,一个用于section 1
,一个用于section 2
,
,默认选择的单选按钮为section 1
,并显示一些文本,但是当客户单击section 2
时,下面没有文本。用来说明我的页面
[*] section 1 [ ] section 2
- section one text when checked radio button
----------------------------------------------
[ ] section 1 [*] section 2
// none text here when section two checked
< Button >
然后在单击按钮并选择第2部分之后,转到另一页,然后返回该部分页面,显示section one text when checked radio button
的文本以为单选按钮选中了section 2
>
当客户返回该页面但仍选中section one text when checked radio button
时,如何隐藏该文本(section 2
)?
这发生在我的Rails应用上
答案 0 :(得分:0)
您可以根据变量的值向包含文本的范围内添加一个类。例如,您可以这样做:
<span class="<%= hide if @variable =='section 2 value' %>">
- section one text when checked radio button
</span>
答案 1 :(得分:0)
如果我猜您要正确执行的操作:这是根据单击哪个单选按钮显示文本的操作。如何将HTML拆分为div并在onlick上显示/隐藏这两个div的ID。
点击第1部分时:
$('#add-doc-modal #show-section1').show();
$('#add-doc-modal #show-section2').hide();
点击第2部分时:
$('#add-doc-modal #show-section2').show();
$('#add-doc-modal #show-section1').hide();
如果这是您的问题,那是最不容易理解的问题。
要隐藏单选按钮并设置为false:
document.getElementById("#id").style.display = "none";
$("#id").prop("checked", false);
显示单选按钮
document.getElementById("#id").style.display = "block";
$("#id").prop("checked", true);