【发布时间】:2017-03-30 03:27:32
【问题描述】:
我无法使此脚本正常运行。
我正在尝试使表单输入的值显示或隐藏操作页面上的不同部分。
例如,下面的 html 代码显示所有标题文本以隐藏开始,但 javascript 函数应根据表单的 GET 值取消隐藏部分。
因此,要显示“自定义”部分,链接将是 http://domain.tld/action.php?custom=on
以下是需要根据表单值显示/隐藏的部分。
<div id="customsection" onload="javascript:customCheck();" style="display:none" class="custom">
<h1>Custom Text</h1>
</div>
<div id="whitesection" onload="javascript:whiteCheck();" style="display:none" class="white">
<h1>White Text</h1>
</div>
<div id="colorsection" onload="javascript:colorCheck();" style="display:none" class="color">
<h1>Colored Text</h1>
</div>
这是我的脚本函数:
function customCheck() {
if ($_GET['custom'] == 'on') {
document.getElementById('customsection').style.display = 'block';
}
else document.getElementById('customsection').style.display = 'none';
}
function colorCheck() {
if ($_GET['color'] == 'on') {
document.getElementById('colorsection').style.display = 'block';
}
else document.getElementById('colorsection').style.display = 'none';
}
function whiteCheck() {
if ($_GET['white'] == 'on') {
document.getElementById('whitesection').style.display = 'block';
}
else document.getElementById('whitesection').style.display = 'none';
}
脚本有什么问题/我该如何解决?
提前致谢!
【问题讨论】:
-
你会考虑 jquery 吗?我将在下面写一个答案,因为看起来您正在将 php 和 javascirpt 混合在一起。
-
@Icewine 我没有使用 jquery 的经验,但如果它适用于这种情况,那么我肯定会使用它。我很确定我的语法不正确,但我认为这是对先前问题的解决方案,所以我尝试了。
标签: javascript forms if-statement get display