“display:none”的元素仍然可见

时间:2011-11-04 19:49:21

标签: html css

正如我在主题中所提到的,即使我将样式设置为不显示下面给出的代码的特定部分,它仍然出现在页面上。我应该将代码的一部分包含在一个单独的表中吗?请提出您可能遇到的问题的建议。

<div id="submit">
<table
    style="font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif"
    ; border="0" cellpadding="5" cellspacing="0" align="center">

    <form id="frm" name="frm" action="http://app1/submitProxy.php"
        method="POST" enctype="multipart/form-data">
        <tr>
            <th colspan="2" bgcolor="#004276"><font color="white">
                    Submit a File 
            </th>
        </tr>
        <tr>
            <td>File:</td>
            <td><input name="upfile" type="file" value="">
            </td>
        </tr>
        <input type="hidden" name="email" readonly="readonly"
            value="<%=user.getUserName()%>" /> <input type="hidden"
            name="reanalyze" value="true" />
        <tr>
            <td>Case or Reference Number:</td>
            <td><input type="text" name="caseno" value="${caseno}" /></td>
        </tr>
<%--            <tr>
            <td>Date acquired:</td>
            <td><input type="text" name="acq" id="acq" readonly="readonly"
                value="${document.frm.acq}" /><strong><a href="#"
                    onclick="cal1.select(document.frm.acq,'anchor1','MM/dd/yyyy'); return false;"
                    title="cal1.select(document.frm.acq,'anchor1','MM/dd/yyyy'); return false;"
                    name="anchor1" id="anchor1"><font face="Helvetica,sans-serif">
                            SELECT</font> </a> </strong></td>
        </tr>
        <tr>
            <td>Type of system acquired from:</td>
            <td><input type="text" name="systemAcquired"
                value="${systemAcquired}" /></td>
        </tr> --%>
        <tr>
            <td>Obtained via:</td>
            <td></td>
        </tr>
        <tr>
            <td><dd>Search Warrant:</dd></td>
            <td><input type="checkbox" name="searchWarrant"
                onclick="showhidefield()" value="Y">
            </td>
        </tr>
<div id='hideablearea' style='display: none;'>
    <tr>
            <td>Search Warrant Number:</td>
            <td><input name="searchWarrantNumber" type="text"
                value="${searchWarrantNumber}" /> <br />
            </td>
        </tr>
        <tr>
            <td>Jurisdiction:</td>
            <td><input name="jurisdiction" type="text"
                value="${jurisdiction}" /> <br />
            </td>
        </tr>
        </div>
    <tr>
        <td><dd>Grand Jury:</dd></td>
        <td><input type="checkbox" name="grandJury" value="Y"
            onclick="checkGrandJury()">
        </td>
    </tr>
    <tr>
        <td><dd>Found in the wild:</dd>
        </td>
        <td><input type="checkbox" name="foundInTheWild" value="Y"
            onclick="checkFoundInTheWild()">
        </td>
    </tr>
    <tr>
        <td><dd>Email:</dd></td>
        <td><input type="checkbox" name="obtainedEmail" value="Y"
            onclick="checkObtainedEmail()">
        </td>
    </tr>
    <tr>
        <td><dd>Other:</dd></td>
        <td><input type="checkbox" name="obtainedOther" value="Y"
            onclick="checkObtainedOther()">
        </td>
    </tr>
    <tr>
        <td>Environment:</td>
        <td><select name="sandboxes[]" size="1">
                <option value="00-0C-29-CF-B8-A6">VMSB1 - Windows 7</option>
                <option value="00-0C-29-0A-AB-9A">VMSB2 - Windows XP</option>
        </select>
        </td>
    </tr>
    <tr>
        <td>Comments:</td>
        <td><textarea name="notes">Add comments here...</textarea><br>

        </td>
    </tr>
    <td colspan="2">
        <center>
            <input type="submit" name="button" value="Submit"
                onclick="onSubmit()" />
        </center>
    </td>
    </form>
</table>
</div>

5 个答案:

答案 0 :(得分:8)

TR之间的DIV是无效的HTML。将“display:none”放在TR本身上。

      </tr>
<div id='hideablearea' style='display: none;'>   <----- invalid
    <tr>

答案 1 :(得分:3)

Arrgh,你打破了桌子:你在两个表格中插入一个'div'标签,这是无效的html。

我建议创建两个单独的表,并隐藏第二个表。要确保它们具有相同的内容,请使用表格和td标记上的“width =”属性。

或者,作为另一种方法,在每个要隐藏的标签上使用“style ='display:none;'”标签,并按类标识切换它们,例如:

<tr class="firstHidden" style="display:none;"> .....</tr>

使用正确的JS库(例如jQuery),一次性切换它们非常简单:

$('.firstHidden').show();

答案 2 :(得分:2)

你不能把表格行放在div里面。最好将代码分成两个表,然后隐藏第二个表。

<div id="submit">
<form id="frm" name="frm" action="http://app1/submitProxy.php"
        method="POST" enctype="multipart/form-data">
<table
    style="font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif"
    ; border="0" cellpadding="5" cellspacing="0" align="center">


        <tr>
            <th colspan="2" bgcolor="#004276"><font color="white">
                    Submit a File 
            </th>
        </tr>
        <tr>
            <td>File:</td>
            <td><input name="upfile" type="file" value="">
            </td>
        </tr>
        <input type="hidden" name="email" readonly="readonly"
            value="<%=user.getUserName()%>" /> <input type="hidden"
            name="reanalyze" value="true" />
        <tr>
            <td>Case or Reference Number:</td>
            <td><input type="text" name="caseno" value="${caseno}" /></td>
        </tr>
<%--            <tr>
            <td>Date acquired:</td>
            <td><input type="text" name="acq" id="acq" readonly="readonly"
                value="${document.frm.acq}" /><strong><a href="#"
                    onclick="cal1.select(document.frm.acq,'anchor1','MM/dd/yyyy'); return false;"
                    title="cal1.select(document.frm.acq,'anchor1','MM/dd/yyyy'); return false;"
                    name="anchor1" id="anchor1"><font face="Helvetica,sans-serif">
                            SELECT</font> </a> </strong></td>
        </tr>
        <tr>
            <td>Type of system acquired from:</td>
            <td><input type="text" name="systemAcquired"
                value="${systemAcquired}" /></td>
        </tr> --%>
        <tr>
            <td>Obtained via:</td>
            <td></td>
        </tr>
        <tr>
            <td><dd>Search Warrant:</dd></td>
            <td><input type="checkbox" name="searchWarrant"
                onclick="showhidefield()" value="Y">
            </td>
        </tr>
        </table>
        <table id='hideablearea' style="display: none; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif"
    ; border="0" cellpadding="5" cellspacing="0" align="center">
    <tr>
            <td>Search Warrant Number:</td>
            <td><input name="searchWarrantNumber" type="text"
                value="${searchWarrantNumber}" /> <br />
            </td>
        </tr>
        <tr>
            <td>Jurisdiction:</td>
            <td><input name="jurisdiction" type="text"
                value="${jurisdiction}" /> <br />
            </td>
        </tr>
        </div>
    <tr>
        <td><dd>Grand Jury:</dd></td>
        <td><input type="checkbox" name="grandJury" value="Y"
            onclick="checkGrandJury()">
        </td>
    </tr>
    <tr>
        <td><dd>Found in the wild:</dd>
        </td>
        <td><input type="checkbox" name="foundInTheWild" value="Y"
            onclick="checkFoundInTheWild()">
        </td>
    </tr>
    <tr>
        <td><dd>Email:</dd></td>
        <td><input type="checkbox" name="obtainedEmail" value="Y"
            onclick="checkObtainedEmail()">
        </td>
    </tr>
    <tr>
        <td><dd>Other:</dd></td>
        <td><input type="checkbox" name="obtainedOther" value="Y"
            onclick="checkObtainedOther()">
        </td>
    </tr>
    <tr>
        <td>Environment:</td>
        <td><select name="sandboxes[]" size="1">
                <option value="00-0C-29-CF-B8-A6">VMSB1 - Windows 7</option>
                <option value="00-0C-29-0A-AB-9A">VMSB2 - Windows XP</option>
        </select>
        </td>
    </tr>
    <tr>
        <td>Comments:</td>
        <td><textarea name="notes">Add comments here...</textarea><br>

        </td>
    </tr>
    <td colspan="2">
        <center>
            <input type="submit" name="button" value="Submit"
                onclick="onSubmit()" />
        </center>
    </td>

</table>
</form>

答案 3 :(得分:2)

您所要做的就是将id='hideablearea' style='display: none;'放入您要隐藏的行中 - 哦,删除div

答案 4 :(得分:0)

谢谢你的帮助。我出于某种原因无法使用您的任何想法。但是,我找到了解决方法。我使用下拉菜单选择“获得通过”选项。因为我只在选择搜查令时想要额外的字段,所以我做了类似以下的事情:

<jsp:include page="template-header-menu.jsp" />



<script type="text/javascript">

function showFields(num){
    container = document.getElementById('field1GoHere');
    container.innerHTML = '';

    if(num == 1){
         container.innerHTML += '<td>Search Warrant Number:</td><td><input name="searchWarrantNumber" type="text" value="${searchWarrantNumber}" /></td>';
    }
    container = document.getElementById('field2GoHere');
    container.innerHTML = '';

    if(num == 1){
         container.innerHTML += '<td>Jurisdiction:</td><td><input name="jurisdiction" type="text" value="${jurisdiction}" /></td>';
    }

}

.
.
.
.
.

</script>

<div id="submit">
<table
    style="font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif"
    ; border="0" cellpadding="5" cellspacing="0" align="center" width=450>

    <form id="frm" name="frm" action="http://app1/submitProxy.php"
        method="POST" enctype="multipart/form-data">
.
.
.
.
.
.
.           <tr>
            <td width=450><font face="Helvetica,sans-serif">Obtained
                    via:* </font>
            </td>
            <td><select onchange="showFields(this.options[this.selectedIndex].value)">
                 <option value="0">Choose:</option>
                <option value="1">Search Warrant</option>
                <option value="2">Grand Jury</option>
                <option value="3">Found in the wild</option>
                <option value="4">Email</option>
                <option value="5">Other</option></select>
            </td>
        </tr>
        <tr id="field1GoHere"></tr>
        <tr id="field2GoHere"></tr>

    <tr>
    <td colspan="2">
        <center>
            <input type="submit" name="button" value="Submit"
                onclick="onSubmit()" />
        </center></td>
    </form>
</table>
</div>
<jsp:include page="template-bottom.jsp" />

因此,在选择下拉菜单时,我想要隐藏的选项出现,我根本不必使用“display:none”。