gpt4 book ai didi

javascript - onclick 按钮仅显示一次 toastr 并将错误消息分组到 toastr

转载 作者:行者123 更新时间:2023-12-02 21:54:09 24 4
gpt4 key购买 nike

我正在使用 toastr jquery 插件。下面是链接

https://github.com/scottoffen/jquery.toaster

我在这里面临两个问题

  1. 目前点击按钮时会显示多个通知(请参阅附图)

    预期:每次点击时应显示一个通知,如果存在通知,则不显示另一个通知。

  2. 对多个通知进行分组的方法

预期:将名称和密码一起作为单个通知

代码

$(".actions").on("click", ".startWorkflowD", function() {

//Disable Start workflow button
$('.startWorkflowD').attr('disabled', 'disabled');

var userDisplayName = $("#HEADER_USER_MENU_POPUP_text").text().toLowerCase();
var actualUserDisplayName = $("#name").val().toLowerCase();

if (userDisplayName != actualUserDisplayName) {
$.toaster({
priority: 'warning',
title: 'Authentication Failed',
message: '<br/>' + 'Please enter valid Name (First name and Last name), to start the workflow.'
});

//Enable start workflow button
$('.startWorkflowD').removeAttr("disabled");

return;
}

var password = $("#Password");

if (password.val().length == 0) {
// password is empty
$.toaster({
priority: 'warning',
title: 'Authentication Failed',
message: '<br/>' + 'Please enter valid Password, to start the workflow.'
});

//Enable start workflow button
$('.startWorkflowD').removeAttr("disabled");
}

});

感谢任何帮助

我尝试了下面的 stackoverflow 答案,我的 toastr 选项中没有 **"preventDuplicates": true,**

toastr (jquery) must only show once

multiple tostr

最佳答案

这可能会对某人有所帮助。这是我做的示例演示。

  • 不允许重复
  • 进度条

选项带有图标

<input type="text" name="name" id="name" placeholder="Name" />
<br>
<input type="password" name="Password" id="Password" placeholder="Password" />
<br>
<input type="button" class="actions" value="Login" />

<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet"
type="text/css">

<script src="https://code.jquery.com/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

<script>
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-right",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}


$(".actions").on("click", function () {
var name = $("#name").val();
var pwd = $("#Password").val();
var errmsg = "";
if (name == "") {
errmsg = "Please enter valid Name (First name and Last name)";
}
if (pwd == "") {
errmsg += " Please enter valid Password";
}
if (errmsg != "")
toastr.error(errmsg + ' to start the workflow.');
});
</script>

关于javascript - onclick 按钮仅显示一次 toastr 并将错误消息分组到 toastr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60051620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com