【发布时间】:2013-06-20 20:01:58
【问题描述】:
我正在尝试在 div 点击时更改我的 toast 的位置类。
positionclass: 没有改为Bottom.?我在这里错过了什么?
以及如何使用
toastr.optionsOverride = 'positionclass:toast-bottom-full-width';
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<head>
<title></title>
<script type ="text/javascript" src ="@Url.Content("~/Scripts/jquery-1.6.4.js")"></script>
<script type ="text/javascript" src ="@Url.Content("~/Scripts/toastr.js")"></script>
<link rel="stylesheet" type="text/css" href="~/content/toastr.css" />
</head>
<script type="text/javascript">
$(document).ready(function () {
// show when page load
toastr.info('Page Loaded!');
$('#linkButton').click(function () {
toastr.optionsOverride = 'positionclass:toast-bottom-full-width';
// show when the button is clicked
toastr.success('Click Button', 'ButtonClick', 'positionclass:toast-bottom-full-width');
});
});
</script>
<body>
<div id ="linkButton" > click here</div>
</body>
更新 1
调试后我注意到来自 toastr.js 的 getOptions 方法被覆盖 'positionclass:toast-bottom-full-width' 到 'toast-top-right'
function getOptions() {
return $.extend({}, defaults, toastr.options);
}
update 2 toastr.js 中的第 140 行未成功扩展 m optionsOverride in to options.??
if (typeof (map.optionsOverride) !== 'undefined') {
options = $.extend(options, map.optionsOverride);
iconClass = map.optionsOverride.iconClass || iconClass;
}
更新 3 职位问题已得到修复,但我必须在下面提到职位类别 3 次。我确信有一种噪音较小的方法可以实现这一点。
$('#linkButton').click(function () {
toastr.optionsOverride = 'positionclass = "toast-bottom-full-width"';
toastr.options.positionClass = 'toast-bottom-full-width';
//show when the button is clicked
toastr.success('Click Button', 'ButtonClick', 'positionclass = "toast-bottom-full-width"');
});
【问题讨论】:
标签: jquery asp.net-mvc toastr