Toastr不会遵循选项

问题描述:

是的,我知道,对于22may上的同一个问题(一周前)有一个答案,但我尝试过相同的解决方案,它在实际“调用”之前指定为toastr脚本,我甚至尝试过:and =但我无法解决问题。Toastr不会遵循选项

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

这一个工程,除了“选项”。 它在屏幕上显示2 toastr

<!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> 

的代码是在头部,如果我把它放在身体也不会在所有的工作中,我甚至尝试:

$(function() {toastr.option.progressBar= true; 
toastr["error"]("We use Cookies!","Cookies!") 
}); 

我也试着设置

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" } 

在身体.. 和几个我甚至无法记起来了.. 我只是不明白为什么它是如此难以设置日选择E ...

如果选项可以在脚本本身的改变,但也有一些我无法找到在那里会更容易..

您可以设置选项作为第三个参数当你打电话给敬酒。

在控制台试试这个:

toastr["error"]("We use Cookies!","Cookies!", {"progressBar": true,"closeButton": true, "positionClass": "toast-top-full-width"}); 

而且,也许你的选择不被读取为readCookie(名称)功能不是由分号封闭