重置 div 标签在警告框关闭后。

huangapple go评论56阅读模式
英文:

Reset div tag after alert has been closed

问题

当满足条件时,我出现了一个错误消息。消息框的角落有一个小叉,以便用户可以关闭消息。然而,一旦关闭了消息,之后再次出现相同的错误时,消息框不再出现。如何“重置”div类以使其重新出现?

@if (condition == true)
{
    <div class="alert">
        <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span>
        <strong>Error!</strong> An error has been identified
    </div>
}

再次满足条件,但错误框不弹出。

英文:

I have an error message that pops up when a condition is met. There is a small cross in the corner of the message box so that the user can get rid of the message. However once this is done and the same error is made later on the message box does not reappear. How can I "reset" the div class so that it reappears?

@if (condition == true)
{
    &lt;div class=&quot;alert&quot; &gt;
         &lt;span class=&quot;closebtn&quot; onclick=&quot;this.parentElement.style.display=&#39;none&#39;;&quot;&gt;&amp;times;&lt;/span&gt;
        &lt;strong&gt;Error!&lt;/strong&gt; An error has been identified
    &lt;/div&gt;
}

The condition is met again but the error box doesn't pop up

答案1

得分: 0

@if (condition == true)
{
<div class="alert" >
<span class="closebtn" onclick="Dissapear">&times;</span>
<strong>Error!</strong> An error has been identified
</div>
}

public void Dissapear()
{
condition = false;
}

我添加了一个方法,但也许你可以在点击事件内部更改条件。

英文:
@if (condition == true)
{
    &lt;div class=&quot;alert&quot; &gt;
         &lt;span class=&quot;closebtn&quot; onclick=&quot;Dissapear&quot;&gt;&amp;times;&lt;/span&gt;
        &lt;strong&gt;Error!&lt;/strong&gt; An error has been identified
    &lt;/div&gt;
}


 public void Dissapear()
    {
        condition = false;
    }

I added a method but perhaps you could change the condition within the onclick event itself

huangapple
  • 本文由 发表于 2023年2月14日 19:06:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75446924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定