以下(非常简单,非常棒)JS脚本正在我的客户的Bigcommerce购物车中使用。它旨在获取给定的BC客户组,并检查给定元素的状态(单选按钮),然后显示给定的选择器,或让它保持隐藏状态。它在除IE之外的每个浏览器中都能正常工作,它正常运行,但从不显示选择器,即使控制台没有显示错误也是如此。 (为什么它以一秒钟的间隔运行?因为BC一次装载四个装置,但来自同一页面。哇!)
这里是否有IE不支持的JS功能?我已经审查了所有的功能,但我没有看到任何内容,但是你知道在几个小时内盯着相同的代码会有多盲目。
[编辑:似乎IE正在拾取脚本中的关键短语,即使innerText不应该这样做。但至少我离解决方案更近了一步!]
<script>
window.onload = setInterval(hideCC, 1000);
function hideCC ()
{
/* Hide CC payment option for below listed groups only */
/* Add new customer groups with comma-separated list (i.e. [39,42,87]) */
var customergroup = [27,32,22,65,2,69,72,74,79,78,87,84,60,61,52,53,54,55,56,57,58,59,62,63,70,83,8,5];
/* Hide CC payment option for those using International Freight */
var intlFreight = document.documentElement.innerText.indexOf('International Freight');
/* Check state of wire transfer button; if it's checked, we don't need to do any of this */
var wireChecked = document.getElementById("radio-bankdeposit").checked;
if (wireChecked == true) {
return;
}
else {
/* If the customergroup belongs to one of those listed above OR the text "International Freight" appears on the page, that will trigger this if */
if(customergroup.indexOf({{{customer.customer_group_id}}}) > -1 || intlFreight > -1 ) {
/* console.log({{{customer.customer_group_id}}}); */
document.querySelector("#micro-app-ng-checkout > div > div > main > ol > li.checkout-step.checkout-step--payment.optimizedCheckout-checkoutStep > div.checkout-view-content > form > fieldset:nth-child(1) > div > ul > li.form-checklist-item.optimizedCheckout-form-checklist-item.form-checklist-item--selected.optimizedCheckout-form-checklist-item--selected").style.display="none";
}
}
};
</script>
答案 0 :(得分:1)
这是&#34; shippingOption-desc&#34;中检查字符串的jQuery版本。类。希望这将解决IE和innerText的问题:)
var intlFreight = $('.shippingOption-desc').text().indexOf('International Freight');