根据警报消息内容执行某些操作
Do something based on the alert message content
我已经创建了一些自定义购物车警报,但目前我遇到了一些脚本运行一些 ajax 响应的问题,这些响应应该在 Business Catalyst 中刷新购物车。
我不确定它是什么,但为了让我有时间研究发生了什么,我需要根据警报消息做一些事情,所以让我们说:
1 件商品已添加到您的购物车,这将做一些window.location.reload();
或者如果它只是说:你需要选择一个尺寸什么都不做
此时此刻,我的警报是:
window.alert = function(message) {
$('.shop-main').addClass('blur');
$('.messageAlert').fadeIn().text(message).prepend('<img src="/images/ui-pieces/shopping-cart.png" width="40" height="40" alt="cart alert"/>');
setTimeout(function() {
$('.messageAlert').fadeOut();
$('.shop-main').removeClass('blur');
// window.location.reload();
}, 4000);
};
请让我知道我在这个阶段可以做到。
关闭时,您需要检查警报并基于此运行代码。
以下是我在BC省所做的:
window.alert = function(text) {
if (text.indexOf("Please choose relevant options before") > -1) {
//CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
$('#choose-option').foundation('reveal', 'open');
} else if (text.indexOf("item(s) added to your cart") > -1) {
//CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
$('#store-modal').foundation('reveal', 'open');
} else if (text.indexOf("Quantity entered is too large, please enter a smaller quantity.") > -1) {
//CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
$('#limited-quantity').foundation('reveal', 'open');
}
};
就我而言,我正在打开页面上的某些模态。代替模态代码,您可以插入自己的 JS。
使用此代码 - 开发 => 布局 => 网上商店 => small_product.html(将以下代码粘贴到页面底部)
<span class="cartalert" style="display:none"></span>
<style>
.cartalert {
position: fixed;
bottom: 10%;
right: 10%;
padding: 15px 20px;
text-align: center;
background: #333;
color: #fff !important;
z-index:999999;
border-radius: 5px;
font-size: 16px;
}
</style>
<script>
$(function() {
window.alert = function(msg) {
msg = msg.replace('ERROR: ','');
$('.cartalert').text(msg).fadeIn().delay(1000).fadeOut()
}
});
</script>
相关文章:
- 单击元素两次后执行操作
- 如何在mvc3中执行操作而不更改当前页面
- jQuery onunload在按下按钮时执行操作
- 如果DOM发生更改,您将如何执行操作
- 在执行所有回调函数后执行操作
- JavaScript 对输入框执行操作
- 如何根据各种复选框状态执行操作
- 对页面重新加载 Jquery 执行操作
- jQuery如果大于则执行操作,但只执行一次
- ngStorage是否异步执行操作
- 如何逐一执行操作
- 只有当输入文本是example.com这样的域时才执行操作
- Javascript数学不起作用,更好的方式来执行操作
- Qubit在控制台中执行操作
- 停止setInterval,直到未执行操作
- 我如何使用javascript对音频标记执行操作
- JS 函数将对象作为输入,并返回一个对象,该对象对作为参数传递的对象执行操作
- 单击时执行操作多个具有相同类的 href
- 在 JavaScript 中传递指定秒数后如何执行操作
- 如何在对用户控件执行操作后调用 Web 服务