我需要通过 javascript 函数更改一次运输承运人下拉菜单和运输方式单选按钮,而不是永远。
但是,当我使用此功能时,当订单 < 5 美元时在 Review and Submit 页面上执行时,它会进入无限循环:
function setFreeSampShipping(){
var options = document.forms['checkout'].shippingcarrierselect.getElementsByTagName('option');
for (i=0;i<options.length;i++){
if (options[i].value == 'nonups'){
document.forms['checkout'].shippingcarrierselect.value='nonups';
document.forms['checkout'].shippingcarrierselect.onchange();
document.location.href='/app/site/backend/setshipmeth.nl?c=659197&n=1&sc=4&sShipMeth=2035';
}
}
}
它是从函数 setSampPolicyElems() 的这一部分中调用的,您可以看到我已将其注释掉以停止循环:
if (carTotl < 5 && hasSampp == 1) {
/*
if (document.forms['checkout'].shippingcarrierselect.value =='ups'){
setFreeSampShipping();
}
*/
document.getElementById('sampAdd').style.display="none";
document.getElementById("custbody_ava_webshiptype").value = "7";//no charge free freight
if (document.getElementById("applycoupon")) {
document.location.href='/app/site/backend/setpromocode.nl?c=659197&n=1&sc=4&kReferralCode=SAMPLE'
}
document.write("<div id='msg'><strong>Sample & Shipping:</strong></span> No Charge. (Your sample order is < $5.)</div>");
}
要查看问题,请转到此处的订单审核和提交页面: https ://checkout.netsuite.com/s.nl?c=659197&sc=4&n=1 (或转到http://www.avaline.com,点击“结帐”,然后登录)
您可以使用以下凭据登录:
电子邮件:test2@gmail.com 密码
:test03
到目前为止,我的解决方案是用这个替换 onchange() 事件触发线,从那以后我没有运行 document.location.href 两次:相反,我在一个 URL 查询字符串中传递了两个变量:
var dropdown = document.getElementById('shippingcarrierselect');
document.body.style.cursor = 'wait';
document.location.href='/app/site/backend/setshipmeth.nl?c=659197&n=1&sc=4&sShipMeth=2035&sShipCarrier='+dropdown.value;