我使用 jquery 作为表单来选择一些选项,当单击单选按钮时,它会显示一个带有选项的新 div,依此类推 4 个 div。
示例:我单击“Spreekwoorden”,打开一个名为“niveau”的 div,当我单击此处的单选按钮时,它会打开“vraagstelling”,在这里我还单击一个单选按钮。
现在我不想要这个并选择Woordenschat。 这必须打开“niveau”->“vraagstelling”->“groep”。 但是当我这样做时,它会记住我之前所做的操作,并立即打开所有 div,并记住我之前单击的单选按钮。
当我从“onderdeel”更改时,脚本不记得单击的单选按钮并且我之前打开过 div,以便当我再次单击单选按钮时出现 div,如何实现这一点?
我把代码放在这里:
[https://jsfiddle.net/gryjjxct/2/][1]jsfiddle[1]
最佳答案
您可以使用一些 jquery - removeAttr("checked")
- 在每次选择选项时清除单选选项:
$('input[name=onderdeel]').click(function () {
if (this.id == "show_groepen") {
$("input[name=vraagstelling]").removeAttr("checked");
$("#niveau").hide();
$("#vraagstelling").hide();
$("#groepen").show('slow');
} else {
$("#groepen").hide('slow');
}
if (this.id == "show_niveau") {
$("input[name=vraagstelling]").removeAttr("checked");
$("#niveau").hide();
$("#vraagstelling").hide();
$("#niveau").show('slow');
} else {
$("#niveau").hide('slow');
}
});
关于javascript - jquery show hide div 但 onchange 记住它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775340/