首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Toastr不会遵循选项

Toastr不会遵循选项
EN

Stack Overflow用户
提问于 2017-05-30 16:24:49
回答 1查看 524关注 0票数 2

是的,我知道,5月22日(一周前)也有同样问题的答案,但我已经尝试了相同的解决方案,它是在实际“调用”toastr脚本之前指定的,我甚至尝试了同时使用:和=,但我无法解决这个问题。

第一个代码是整个页面,包括“检查是否设置了cookie,如果没有,则显示toastr并设置cookie”脚本。

这个是有效的,除了“选项”。它在屏幕上显示2个toastr

代码语言:javascript
复制
<!DOCTYPE html><html><head><meta charset=utf-8>

<link href="https://my.site.se/js/toastr.css" rel="stylesheet" type="text/css" />

<script src= "https://my.site.se/js/jquery-3.2.1.js"></script>
<script src="https://my.site.se/js/toastr.js"></script>
<!-- createCookie funktion -->
<script>

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}


</script>
<script>
<!-- see if the i agree cookie is set, else send them to the info page -->

function readCookie(name) {
    var nameEQ = name + "=";

    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

    }



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

}



$(function () {

toastr.options.closeButton: true;
toastr.options.progressBar=true;
toastr["error"]("We use Cookies!","Cookies!")

});



$(function () {toastr["info"]("We have now created a cookie that prevents this information from being displayed again, unless you remove the cookie of course\n Read the terms page for more info\n To delete ALL your cookies, press the delete cookies button!")});


}

</script>
</Head>
<body>

<script>
readCookie('acceptterms');
</script>
<script>
createCookie('acceptterms','yesIdo',3650);
</script>

代码在头部,如果我把它放在主体中,它根本不会起作用,我甚至尝试过:

代码语言:javascript
复制
$(function () {toastr.option.progressBar= true;
toastr["error"]("We use Cookies!","Cookies!")
});

我还尝试将

代码语言:javascript
复制
toastr.options = {   "closeButton": true,   "debug": false,   "newestOnTop": false,   "progressBar": true,   "positionClass": "toast-top-left",   "preventDuplicates": false,   "showDuration": "300",   "hideDuration": "1000",   "timeOut": "5000",   "extendedTimeOut": "1000",   "showEasing": "swing",   "hideEasing": "linear",   "showMethod": "fadeIn",   "hideMethod": "fadeOut" }

在身体里..。还有一些我现在甚至不记得了..。我就是不明白为什么设置选项这么难...

如果可以在脚本本身中更改选项,那会更容易,但我在其中找不到一些选项。

EN

回答 1

Stack Overflow用户

发布于 2017-07-21 08:01:37

您可以在调用toast时将这些选项设置为第三个参数。

在您的控制台中尝试以下操作:

代码语言:javascript
复制
toastr["error"]("We use Cookies!","Cookies!", {"progressBar": true,"closeButton": true, "positionClass": "toast-top-full-width"});

此外,您的选项可能没有被读取,因为readCookie(名称)函数不是用分号结束的

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44257138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档