簡體   English   中英

Firefox無法正確顯示和隱藏我的表格。 僅在按鈕上顯示標題,不按行

[英]Firefox won't show and hide my table properly. Only Shows header on button press not row

Firefox無法正確顯示和隱藏我的表格。 僅在按鈕上顯示標題,不按行。

基本上,我想要的是用戶單擊按鈕時要顯示的ID為“ HideMe”的列標題和具有相同ID的行。 這在Chrome中完美運行,但在Firefox中則無法

<html>

<head>
    <title>Show and Hide Javascript won't work in Firefox</title>
    <style>
        #HideMe {
            display:none;
        }
    </style>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script>
        jQuery(document).ready(function ($) {
            $('.ShowPassword').click(function () {
                $(HideMe).show();
            });
        });
    </script>
</head>

<body>
    <table>
        <tr>
            <th>ID Number</th>
            <th>First Name</th>
            <th>Middle Name</th>
            <th id="HideMe">Password</th>
        </tr>
        <tr>
            <td>2121</td>
            <td>Mike</td>
            <td>Daniel</td>
            <td id="HideMe">Password</td>
        </tr>
        <button class="ShowPassword">Show Password</button>
</body>

這絕對不對

$(HideMe).show();

您可能想要執行以下操作:

$('#HideMe').show();

內容: http : //jsfiddle.net/JS7tK/5/

起初我沒有注意到,但正如bandi在他的注釋ID中指出的那樣,應該是唯一的。 因此,嘗試執行以下操作:

<html>
    <head>
        <title>Show and Hide Javascript won't work in Firefox</title>
        <style>
            .HideMe {
                display:none;
            }
        </style>
        <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
        <script>
            jQuery(document).ready(function ($) {
                $('.ShowPassword').click(function () {
                    $('.HideMe').show();
                });
            });
        </script>
    </head>

    <body>
        <table>
            <tr>
                <th>ID Number</th>
                <th>First Name</th>
                <th>Middle Name</th>
                <th class="HideMe">Password</th>
            </tr>
            <tr>
                <td>2121</td>
                <td>Mike</td>
                <td>Daniel</td>
                <td class="HideMe">Password</td>
            </tr>
            <button class="ShowPassword">Show Password</button>
    </body>
<html>

我不使用jQuery,但是通常來說,最好將一個span放在&隱藏之內而不是隱藏該單元格,因為這樣做會導致表格不平衡,因此某些瀏覽器不允許這樣做並不奇怪它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM