【发布时间】:2016-07-28 15:08:32
【问题描述】:
我想我越来越近了,但它不起作用。非常感谢您的观看!
这有效:在表单 (index.html) 上,当用户选择“包含”单选时,内容会显示在表单上,然后在提交后显示在 welcome.php 上。它对两者都隐藏起来。
问题:如果在animalvillas1,animalvillas2和animalvillas3上没有单独输入值,我想做同样的事情并在提交时隐藏welcome.php上的内容。
请参阅下面的 index.html 和 welcome.php:
index.html
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("input[name='animalvillas']").click(function () {
if ($("#chkYes1").is(":checked")) {
$("#dvanimalvillas").show();
} else {
$("#dvanimalvillas").hide();
}
});
});
</script>
</head>
<form name="create" action="welcome.php" method="post">
<span><strong>Lodge Villas - Jambo</strong></span><BR />
<label for="chkYes1">
<input type="radio" id="chkYes1" name="animalvillas" value="Y" />
Include
</label>
<label for="chkNo1">
<input type="radio" id="chkNo1" name="animalvillas" value="N" checked />
Exclude
</label>
<hr />
<div id="dvanimalvillas" style="display: none">
$<input type="text" name="animalvillas1" size="3" /> - Value Studio - Standard View (Parking View) <br>
$<input type="text" name="animalvillas2" size="3" /> - Deluxe Studio - Standard View (Water / Pool) <br>
$<input type="text" name="animalvillas3" size="3" /> - Deluxe Studio - Savanna View <br>
</div>
<input type="submit" />
</form>
欢迎.php
<div id="dvanimalvillas" <?php echo ($_POST['animalvillas'] == "N") ? 'style="display:none;"' : '' ; ?>>
<?php if (!empty($animalvillas1)) { ?>$<?php echo $_POST["animalvillas1"]; ?> - Value Studio - Standard View <BR><?php } ?>
<?php if (!empty($animalvillas2)) { ?>$<?php echo $_POST["animalvillas2"]; ?> - Deluxe Studio - Standard View <BR><?php } ?>
<?php if (!empty($animalvillas3)) { ?>$<?php echo $_POST["animalvillas3"]; ?> - Deluxe Studio - Savanna View <BR><?php } ?>
</div>
【问题讨论】:
-
是的,抱歉,我把这个 sn-p 拿出来展示在这里,忘了拿出来
-
使用 if(isset($_POST['yourvar']) ....
-
谢谢莱米。我使用了这个,但如果值留空,该行仍然显示。
-
$ - Value Studio - 标准视图
-
愚蠢的问题,你有 echo $animalvillas1/2/3 吗?显示什么值?
标签: javascript php jquery html