【发布时间】:2021-01-08 13:09:29
【问题描述】:
单击 asp.net 按钮时,我想调用此函数来显示小吃栏。然而,它未能如愿。 我尝试将按钮放在表单 runat="server" 之外,它可以工作。 但是,我需要它位于表单 runat="server" 标记内并单击 asp.net 按钮,我该如何解决这个问题?
主页.aspx
<style>
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
font-size: 17px;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@-webkit-keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
@keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
</style>
<script>
function myFunction() {
var x = document.getElementById("snackbar");
x.className = "show";
setTimeout(function () { x.className = x.className.replace("show", ""); }, 3000);
}
</script>
<form runat="server">
<asp:LinkButton ID="reportThreadBtn" class="btn btn-default btn-sm" ForeColor="red" runat="server" OnClick="myFunction()" Font-Size="Medium"><i class="glyphicon glyphicon-flag"></i></asp:LinkButton>
</form>
【问题讨论】: