You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

网站悬浮购物车字体样式设置失效问题求助

问题解决方法

你的问题出在三个地方:无效的HTML属性、未闭合的标签,以及JS字符串中引号的嵌套冲突,按下面的方法修改就能同时实现样式生效和购物车正常显示:

关键修正点

  • 把错误的_target_改成标准的target="_blank"(这是导致购物车消失的核心原因之一)
  • 闭合未结束的<strong>标签,原来的代码里<strong>VIEW CART</a>是错误的,要写成<strong>VIEW CART</strong></a>
  • 在JS的document.write字符串里,用单引号包裹style的属性值,避免和外层的双引号冲突(不需要额外转义,更稳妥)

修改后的核心代码行

替换你代码中那行document.write的a标签部分:

document.write("<tr><td colspan=\"2\"><a href=\"https://ww6.aitsafe.com/cf/review.cfm?userid=85247813&return=https://farragio.com/collection\" target=\"_blank\" style='font-weight:bold; color:#cb8f42;'><strong>VIEW CART</strong></a></td></tr>");

完整修改后的代码

<!-- Begin Mal's floating cart Form -->
<div style="position:fixed; top:75px; right:30px; width:125px; border-radius:5px; padding:5px; font-family:Verdana, sans-serif; font-size:0.85em; font-weight:bold; border:none; background-color:none;">
<script type="text/javascript">
//<![CDATA[
// nothing to touch here
function SetCookie(cookieName,cookieValue,mins){
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 60000*mins);
document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
function ReadCookie(cookieName){
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return ""; 
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
var loc = document.location;
var cookieResult = ReadCookie("gt_mals_total");
if (loc.search){
var search = loc.search.slice(1);
if (search.indexOf("qty") >= 0){
SetCookie('gt_mals_total',search,30); //30 mins
}
}

function deleteCookie(cookieName) {
if (document.cookie != document.cookie) {
index = document.cookie.indexOf(cookieName);
} else {
index = -1;
}
if (index == -1) {
document.cookie=cookieName+"=GONEcbEndCookie; expires=Monday, 19-Aug-1996 05:00:00 GMT";
}
//document.location.href = document.location.href;
//to reload without queryString parameters, use the line below instead
document.location = document.location.href.substring(0,document.location.href.indexOf("?"));
} 

// end of nothing to touch here

// adjust the width below to suit your needs
document.write("<table class=\"total\">");
// end of adjust the width below to suit your needs

// nothing to touch here
var cookieResult = ReadCookie("gt_mals_total");
if (cookieResult == ""){
document.write("<tr><td colspan=\"2\" style=\"align:center\"><strong>CART</strong><br>Items: 0<br>Total: $0.00</td></tr>");
} else {
var valsArray = cookieResult.split("&");
for (i in valsArray){
var thisValPair = valsArray[i];
var thisValArray = thisValPair.split("=");
var thisName = thisValArray[0];
var thisVal = thisValArray[1];
// end of nothing to touch here

if (thisName == "qty"){
document.write("<tr><td>Items:</td><td style=\"align:right\">" + Math.floor(thisVal) + "</td></tr>");
}
if (thisName == "tot"){
document.write("<tr><td>Total:</td><td style=\"align:right\">" + "$" + thisVal + "</td></tr>");
// change the above "£" symbol to your currency symbol, example "$".
}
}
// 修改后的核心代码
document.write("<tr><td colspan=\"2\"><a href=\"https://ww6.aitsafe.com/cf/review.cfm?userid=85247813&return=https://farragio.com/collection\" target=\"_blank\" style='font-weight:bold; color:#cb8f42;'><strong>VIEW CART</strong></a></td></tr>");
// change the return url to your page url above
}
document.write("</table>");
//]]>
</script>
</div>
<!-- End Mal's floating cart Form -->

为什么原来的写法失效?

  1. _target_是无效属性,浏览器解析时会认为HTML结构错误,直接隐藏或忽略整个元素
  2. 未闭合的<strong>标签破坏了HTML层级,导致购物车模块的DOM结构异常
  3. 用转义双引号包裹style时,可能被网站的代码过滤或转义机制二次处理,导致样式属性失效;改用单引号则不会和外层的双引号冲突,解析更稳定

内容的提问来源于stack exchange,提问作者ampro415

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 09:42:07