javascript - 我想使用位置功能向#cart-total-remove 添加一个类我尝试了很多方法但没有奏效
问题描述
这是购物车成功功能
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
$('#cart > button').html('<span id="cart-total-remove"><img src="http://localhost/nerv/image/catalog/icons/bag.png"/> ' + json['total'] + '</span>');
}, 100);
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
我尝试添加类更改删除以稍后对其进行样式设置
$(document).ready(function() {
if ( window.location.href == 'http://localhost/nerv/index.php?route=common/home' ){
$("#cart #cart-total-remove img").removeClass("change-remove");
} else {
$("#cart #cart-total-remove img").addClass("change-remove");
console.log(window.location.href);
}
});
这是我的 CSS 代码
#cart #cart-total-remove img {
filter: invert(1);
}
#cart #cart-total-remove img.change-remove{
filter: none;
}
任何帮助,将不胜感激
解决方案
在这里检查你的两个条件是否有效
$(document).ready(function() {
if ( window.location.href == 'http://localhost/nerv/index.php?route=common/home' ){
$("#cart-total-remove img").removeClass("change-remove");
} else {
$("#cart-total-remove img").addClass("change-remove");
console.log(window.location.href);
}
});
推荐阅读
- c# - 如何创建其构造函数需要委托函数参数的泛型类型实例?
- r - R - 过滤数据中的负峰值和正峰值
- node.js - VS Code 中的终端无法执行节点命令行
- javascript - React Native - 来自 JSON 的地图数据可以显示为文本,但不能显示为地图标记坐标
- reactjs - 我想创建反应应用程序,但我不能。任何帮助将不胜感激
- r - 在 Shiny 中创建一个带有增量的 valueBox?
- postgresql - Postgres 持续显示高 CPU 使用率
- reporting-services - 同步 SSRS 中图表的系列组颜色
- nuget - 为什么我在推送到 myget repo 时会出错
- laravel - 模拟 Laravel Eloquent save() 方法