【发布时间】:2017-08-27 22:06:23
【问题描述】:
我被难住了!!!我得到了漂亮的结果,但是当用户选择某些内容时,我无法让相关文本“仅”显示。就像现在一样,文本是静态的,并且始终显示,无论用户是否选择了答案。
例如。 “什么样的动物:”在结果页面上,即使用户没有为它选择答案!如果没有相关答案,这就是不需要显示的内容。
我的 HTML:
<!-- SHOW/HIDE TEXT FIELD -->
<!-- IF BITTEN ANIMAL="YES" or BITTEN "BOTH" Show Field -->
<div id="hidden_textfield10" style="display:none;">
<p class="data_bold">What Kind of Animal</p><div class="data_small">What kind of animal has your pet bitten? Check all that apply:</div>
<label for="Wild"><input class="form_style" type="checkbox" value="Wild" id="Wild" name="whatKindofAnimal[5]" />Wild</label><br />
<label for="Bird"><input class="form_style" type="checkbox" value="Bird" id="Bird" name="whatKindofAnimal[4]" />Bird</label><br />
<label for="Cat"><input class="form_style" type="checkbox" value="Cat" id="Cat" name="whatKindofAnimal[3]" />Cat</label><br />
<label for="Dog"><input class="form_style" type="checkbox" value="Dog" id="Dog" name="whatKindofAnimal[2]" />Dog</label><br />
<label for="Other-Animal"><input class="form_style" type="checkbox" id="Other-Animal" name="whatKindofAnimal[1]" onclick="if(!this.checked) document.getElementById('otherKindofAnimal').value='' " />Other</label>
<!-- IF BITTEN ANIMAL="Other" Show Field -->
<div class="Other-Animal" style="display:none;">
<input class="form_style" type="text" placeholder="Please Specify" id="otherKindofAnimal" name="whatKindofAnimal[1]" />
</div>
<!-- END "Other" Field -->
PHP:
<p class="data_answers">
<?php if (isset($_POST['whatKindofAnimal'])) {echo '<strong>What Kind of Animal:</strong> '; $name = $whatKindofAnimal = implode(', ', array_filter($_POST['whatKindofAnimal'])); echo htmlspecialchars($whatKindofAnimal);} ?>
我一直在整个页面中使用此 PHP 代码的第一部分作为单选按钮,它运行良好!这就是我在其他地方为单选按钮设置的方式......并且相关文本仅在用户实际选择答案时显示。
<p class="data_answers">
<?php if (isset($_POST['bite-reported-human'])) {echo '<strong>Bite Reported:</strong> '; echo htmlspecialchars($_POST['bite-reported-human']);} ?></p>
在这种情况下,“Bite Reported:”在结果页面上保持不可见,除非已为其选择答案。
请帮忙????
在此先感谢您, 特蕾西
【问题讨论】: