简体   繁体   English

单击时使按钮消失

[英]Make button disappear when clicked

I have the following code:我有以下代码:

<script>
    function hidenow(id) {
        var divelement = document.getElementById(id);

        if(divelement.style.display == 'none')
                divelement.style.display =='block'; 
        else
                divelement.style.display = 'none';
                hidenow = button.style.visibility = "hidden";
    }
</script>

And

<br>
<p>Programma's waarop u kunt abonneren:</p>
<form action="#" enctype="multipart/form-data" method="post">
    <?php wp_nonce_field( 'set_programma_action', 'set_programma' ); ?>
    <table>
        <?php foreach ( $retrieve_data as $retrieved_data ) { ?>
            <tr>
                <th>Programma:</th>
                <td id="hideit" style="vertical-align: middle;">
                <?php
                 echo $alreadysub; echo esc_html( $retrieved_data->Anaam );
                 ?>
                 </td>
                <th>
                    <button id="hidebutton('hideb')" onclick="hidenow('hideit')" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>
                </th>
            </tr>
        <?php } ?>
    </table>
</form>

And

<br> 
<p>De programma's waarop u geabonneerd bent:</p>
<form action="#" enctype="multipart/form-data" method="post">
    <?php wp_nonce_field( 'set_programmatest_action', 'set_programmatest' ); ?>
    <table>
        <?php foreach ( $retrieve_data as $retrieved_data ) { ?>
            <tr>
                <th>Programma:</th>
                <td style="vertical-align: middle;"><?php echo esc_html( $retrieved_data->meta_value ); ?></td>
                <th>
                    <button name="programmatest" type="submit" id="button" value="<?php echo esc_attr( $retrieved_data->meta_value ); ?>">Abonnement opzeggen</button>
                </th>
            </tr>
        <?php } 
        ?>
    </table>
</form>

When the button is clicked, the element successfully disappears.单击按钮时,元素成功消失。 The button however, does not.然而,按钮没有。 I do not know how to make sure the button itself also disappears.我不知道如何确保按钮本身也消失。 I have tried onClick = button.style.visibility = "hidden";我试过onClick = button.style.visibility = "hidden"; but it does not give any result.但它没有给出任何结果。

How can I make sure that when I click the button, the button itself along with the element disappear (permanently)?如何确保当我单击按钮时,按钮本身和元素一起消失(永久)?

在此处输入图像描述

change改变

<button id="hidebutton('hideb')" onclick="hidenow('hideit')" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>

to

<button id="hide" onclick="hidenow('hide')" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>

You can't set a ID as a function (I'm assuming that's what you tried to do)您不能将 ID 设置为 function (我假设这就是您尝试做的)

That should fix it那应该解决它

EDIT:编辑:

If you want to hide button after the form is submitted just set the isset($_POST['programma' if you set it do not show button if form is not submitted it will show.如果您想在提交表单后隐藏按钮,只需设置isset($_POST['programma'如果您设置它,则不显示按钮,如果未提交表单,它将显示。

replace your button code with code below.用下面的代码替换您的按钮代码。

if (isset($_POST['programma'])) {
  echo "";
} else  {
  echo '<button id="hidebutton" style="display:block" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>';
}

Other wise you would need to store information if form is submitted in cookie or PHP Session and after reading that info show hide based on that with PHP/JS.否则,如果表单在 cookie 或 PHP Session 中提交,并且在阅读该信息后显示基于 PHP/JS 的隐藏信息,则需要存储信息。

 function hidenow(id) { var divelement = document.getElementById(id); var button = document.getElementById("hidebutton"); if(divelement.style.display == 'none') divelement.style.display ='block', button.style.display = "block"; else divelement.style.display = 'none', button.style.display = "none"; }
 <br> <p>Programma's waarop u kunt abonneren:</p> <form action="#" enctype="multipart/form-data" method="post"> <?php wp_nonce_field( 'set_programma_action', 'set_programma' ); ?> <table> <?php foreach ( $retrieve_data as $retrieved_data ) {?> <tr> <th>Programma:</th> <td id="hideit" style="vertical-align: middle;"> <?php echo $alreadysub; echo esc_html( $retrieved_data->Anaam ); ?> </td> <th> </th> </tr> <?php }?> </table> </form> <button id="hidebutton" style="display:block" onclick="hidenow('hideit')" name="programma" type="submit" value="<?php echo esc_attr( $retrieved_data->Anaam ); ?>">Abonneer</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM