0

我想在单击单选按钮时隐藏我的 div,但我一生都无法弄清楚。这是我的代码:

 <li>
     Residential&nbsp;&nbsp;&nbsp;
     <input type="radio" name="fee" id="residential" class="app_fee"
            value="<?php echo "$applicationFee_residential" ?>"
            onChange="mech_application.fee1.value = eval(mech_application.residential.value)"
            <?php if (isset($_POST['fee'])) {
                      print($residentialYes ? "CHECKED" : "");
            } ?> />
 </li>

 <li>
     Apartment/Commercial
     <input type="radio" name="fee" id="apartment" class="app_fee"
            value="<?php echo "$applicationFee_Apartment" ?>"
            onChange="mech_application.fee1.value = eval(mech_application.apartment.value)"
            <?php if (isset($_POST['fee'])) {
                      print($apartmentNo ? "CHECKED" : "");
            } ?> />
 </li>

 <li>
     Revision&nbsp;
     <input type="radio" name="fee" id="revision" class="app_fee"
            value="<?php echo "$revision" ?>"
            onChange="mech_application.fee1.value = eval(mech_application.revision.value)"
            <?php if (isset($_POST['revision'])) {
                      print($revisionYes ? "CHECKED" : "");
            } ?> />
     <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') {
               if (!isset($_POST['fee'])) {
                   $problem = TRUE;
                   print '<p class="error">Please select the application type</p>';
                   $error = TRUE;
                }
           }?>
  </li>

我想在 Residential 或 Apartment 或单击时隐藏此 div,并在单击修订时显示它:

 <div class="revision_hidden">
     Application ID:
     <input type="text" name="revision_application_id" size="12" maxlength="40"
            value="<?php if (isset($_POST['revision_application_id'])) {
                             print htmlspecialchars($_POST['revision_application_id']);
                    } ?>"
            placeholder="Application ID"/>
 </div>

任何和所有的帮助表示赞赏!谢谢!

4

2 回答 2

2

您可以使用 jQuery 轻松隐藏元素。

$('#id_of_div').hide()

要在单击的单选按钮上执行某些操作,请使用更多 jQuery

$('#id_of_radioBtn').clicked(function(){
   //do something
});
于 2013-07-23T18:48:32.163 回答
2

给你的 div 一个 id:

<div class="revision_hidden" id="my_div"> ...

为您的单选按钮添加一个 onclick 函数:

<input type="radio" name="fee" id="residential" onclick="my_function(this)" ...
<input type="radio" name="fee" id="apartment" onclick="my_function(this)" ...
<input type="radio" name="fee" id="revision" onclick="my_function(this)" ...

并添加一个 JavaScript 函数:

function my_function(elm)
{
    if(elm == document.getElementById('residential') || elm == document.getElementById('apartment'))
    {
        //document.getElementById('my_div').style.visibility = "hidden";
        document.getElementById('my_div').style.display = "none";
    }
    else if(elm == document.getElementById('revision'))
    {
        //document.getElementById('my_div').style.visibility = "visible";
        document.getElementById('my_div').style.display = "block";
    }
}
于 2013-07-23T18:52:34.443 回答