这是我想在我的ASP中启动它的jQuery函数。我想要的是在我在ASP代码中调用它之后创建一个动态函数。它需要:
<a> string alert</a>
)中用于通知用户错误的字符串此外,我创建了一个var(计数器)来防止多次触发此函数。
因此,第一次触发该函数时,它将递增(计数器+ = 1)。之后它将等待一段时间(授予用户使用dismiss&#34;关闭&#34; bootstrap警报行为的权限)。
因此,如果用户采取行动&#34;关闭&#34; <div alert>
将被关闭,计数器将返回其初始值(0)
任何专家都可以帮助我。谢谢。
<asp:TextBox runat="server" ID="txtGroupName" CssClass="form-control" onkeypress="PromptAlert('txtGroupName_alert','alert alert-danger','this is alert string')" />
<div class="alert alert-dismissible" id="txtGroupName_alert"></div>
var $Counter = 0;
function PromptAlert(divID, alertType, alertString) {
if ($Counter != 0) {
this.preventDefault(); //prevent fire this function
} else {
$("#" + divID).prepend("<a id='thisA' href='#' data-dismiss='alert' aria-Label='close'>" + alertString + "</a>"); //add to div those elements
$("#" + divID).addClass(alertType); //add the alert type written by programmer
$Counter += 1; //add the counter +1 to prevent the funvtion to fire many times
$("#" + divID).show(); //show the div alert
$("#thisA").clik(function() {
$(this).data('clicked', true)
});
if ($("#thisA").data('clicked') == true) //Check if it is clicked
{
$Counter = 0;
$("#" + divID).hide(); //hide the alert div
} else if ($("#thisA").data('clicked') == false) {
$("#thisA").delay(12000).keypress(); //if keypress is not fired by the user before this delay fire it automatically
$Counter = 0; // return the counter to 0 to prevent firing the same function many times
}
}
}