Javascript 在多个选择框上显示基于php if语句的div
这个问题在其他线程中得到了部分回答,但我无法理解完整的代码。基本上,我有5个选择框,用户从每个框中选择答案,然后在他们完成后,我想根据答案显示一个div-自动显示或需要按下按钮显示 例如: 。。。。诸如此类Javascript 在多个选择框上显示基于php if语句的div,javascript,php,html,Javascript,Php,Html,这个问题在其他线程中得到了部分回答,但我无法理解完整的代码。基本上,我有5个选择框,用户从每个框中选择答案,然后在他们完成后,我想根据答案显示一个div-自动显示或需要按下按钮显示 例如: 。。。。诸如此类 Else if option1 = **ans3**, option2 = **ans3**, option3= **ans3**, option4 = **ans3**, option5 = **ans3** then show div3 有人对具体的方法有什么想法吗 非常感谢 Bre
Else if option1 = **ans3**, option2 = **ans3**, option3= **ans3**, option4 = **ans3**, option5 = **ans3** then
show div3
有人对具体的方法有什么想法吗
非常感谢
Brent如果我理解得很清楚,当用户选中其中一个复选框时,会显示相应的div吗 在PHP中,您必须更改页面:当用户选择一个框时,他必须提交表单,您可以使用以下命令显示相应的div:
echo '<div> ... </div>'
在Javascript中,用户不必提交任何表单。
首先输入div1、div2等,并显示:无。
处理方框上的onChange事件。在您的事件中,将相应div的“display”css选择器更改为“box”或“inline”或您想要的任何内容 那些逗号是什么意思?逻辑与? 如果是: 现在,是时候问:这是你的家庭作业吗?如果是这样,下次最好不要这样做 您也可以使用jQuery在客户端执行此操作,而无需刷新页面 您只需在对象数组中定义条件:
conditions = [
{
div: '#div1', // div id
conditions: { // you can have any combination of options
option1: 'answer1',
option2: 'answer2'
}
},
{
div: '#div2',
conditions: {
option1: 'answer1',
option2: 'answer3',
option3: 'answer2'
}
}
];
这是一个演示:您是否尝试对其进行编程?是否有一些代码?把它粘贴到JSFIDLE上。这个例子正是我所追求的hutchbat!非常感谢。Sp出于某种原因,这对我不起作用。我能不能把我的代码给你看看,看看你是否知道我是如何破坏了你的优秀作品的。基本上,一旦所有的选择框都填好了,main content div中的所有内容都会被赋予hide类…@user3762340当然!为什么不呢?当条件满足时,我的示例将起作用。是的,我可以看到它工作得很好-它将是我-出于某种原因,一旦选择框完全正确,就会显示div,但主内容潜水中的所有内容都会添加has class=hide。你需要我做什么。你介意我把代码发到你的商务邮件中吗?这个评论区有550个字符,谢谢你的帮助。我喜欢这个主意,但没法实现。
<?php
$answer = array(
1 => "answer1",
2 => "answer2"
);
$options = $_GET['options'];
switch ($options) {
case array($answer1,$answer1,$answer1,$answer1):
echo "<div>div1</div>";
break;
case array($answer2,$answer1,$answer1,$answer1):
echo "<div>div2</div>";
break;
case array($answer2,$answer2,$answer1,$answer1):
echo "<div>div3</div>";
break;
case array($answer2,$answer2,$answer2,$answer1):
echo "<div>div4</div>";
break;
}
?>
<form method="post">
<select name="options[]">
<option>answer1</option>
<option>answer2</option>
</select>
<br />
<select name="options[]">
<option>answer1</option>
<option>answer2</option>
</select>
<br />
<select name="options[]">
<option>answer1</option>
<option>answer2</option>
</select>
<br />
<select name="options[]">
<option>answer1</option>
<option>answer2</option>
</select>
<br />
</form>
conditions = [
{
div: '#div1', // div id
conditions: { // you can have any combination of options
option1: 'answer1',
option2: 'answer2'
}
},
{
div: '#div2',
conditions: {
option1: 'answer1',
option2: 'answer3',
option3: 'answer2'
}
}
];