吐司机:吐司顶部居中;t第一次点击按钮就不会被应用
Toastr: toast-top-center doesn't get applied at the first click of the button
单击按钮时,消息显示在右上角。只有在一到两次尝试之后,它才会被定位在顶部中心。但当提交表格时,它应该在第一次点击时位于顶部中心。有人能告诉我为什么会这样,以及如何纠正吗?我已经包含了下面的代码片段。
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<link rel="stylesheet"
href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
</head>
<body>
<p>toast-top-center</p>
<button onclick="myFunction()">Click Here</button>
<p id="demo"></p>
<script>
function myFunction() {
Command: toastr["error"]
("I'm not in the top-center!")
toastr.options = {
"closeButton" : false,
"debug" : false,
"newestOnTop" : false,
"progressBar" : false,
"positionClass" : "toast-top-center",
"preventDuplicates" : false,
"onclick" : null,
"showDuration" : "300",
"hideDuration" : "1000",
"timeOut" : "5000",
"extendedTimeOut" : "1000",
"showEasing" : "swing",
"hideEasing" : "linear",
"showMethod" : "fadeIn",
"hideMethod" : "fadeOut"
}
}
</script>
</body>
</html>
我认为错误是因为您在读取选项之前运行了toast。
这就是为什么第一个吐司在右上角。
在你的功能结束时运行吐司,它就会起作用。
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<link rel="stylesheet"
href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
</head>
<body>
<p>toast-top-center</p>
<button onclick="myFunction()">Click Here</button>
<p id="demo"></p>
<script>
function myFunction() {
toastr.options = {
"positionClass" : "toast-top-center",
"closeButton" : false,
"debug" : false,
"newestOnTop" : false,
"progressBar" : false,
"preventDuplicates" : false,
"onclick" : null,
"showDuration" : "300",
"hideDuration" : "1000",
"timeOut" : "5000",
"extendedTimeOut" : "1000",
"showEasing" : "swing",
"hideEasing" : "linear",
"showMethod" : "fadeIn",
"hideMethod" : "fadeOut"
}
Command: toastr["success"]
("I'm in the top-center!")
}
</script>
</body>
</html>
这是1.22版本中的一个错误,只需从GitHub下载当前版本即可。
Toast Github链接
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 多个单选按钮组相互干扰
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- Javascript按钮下拉列表
- jquery试图按名称获取按钮位置
- 漂亮照片图片库中的Facebook赞按钮
- 扩展移相器按钮类不工作
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 单击按钮以等待单击按钮
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 如何从querySelectorAll中获取按钮类型
- 如果没有互联网连接,我想显示吐司,不知道该怎么做
- 在具体吐司中设计通知/警报的干净方法
- 吐司通知'覆盖'
- 只有当应用程序被激活时,吐司通知才会弹出
- Windows phone 8.1 javascript+html本地吐司通知
- 吐司机:吐司顶部居中;t第一次点击按钮就不会被应用
- 吐司在煎茶触摸中的实现