2016-07-27 31 views
-1

這應該很容易,不知道爲什麼它不起作用。如果我刪除if!empty,div hide正常工作。如果變量爲空,我不想顯示該行。隱藏內容,如果變量爲空[簡單]

[編輯:對不起,留下的index.html出]

的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" onsubmit="return validateForm();"> 
<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> 

的welcome.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> 
+0

so'($ x =='N')|| ($ x =='')'? –

+0

變量和'$ _POST'鍵之間的關係是什麼,例如'$ animalvillas1'和'$ _POST [「animalvillas1」]'? –

+0

感謝您的回覆,我編輯了OP以包含index.html – plzdonthackme

回答

0

使用jQuery ...

If (yourVariable <= 0){ 
    $('dvanimalvillas').hide(); 
} 
+0

感謝您的回覆,我編輯了OP以包含index.html。這將澄清我想要做的事情。 – plzdonthackme