javascript 函数不会停止循环 - 它位于 netsuite 网站上
我需要通过 JavaScript 函数更改一次运输承运人下拉菜单和运输方式单选按钮,而不是永远更改。
但是,当我使用此功能时,当订单 < 时,该功能会在“审核和提交”页面上执行。 $5,它进入无限循环:
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,点击“结帐”,然后登录)
您可以使用以下凭据登录:
电子邮件:[电子邮件受保护]
通过: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;
I need to change the shipping carrier drop-down and shipping method radio button once via a javascript function, not forever.
However, when I use this function, which executes when on the Review and Submit page when the order is < $5, it goes into an endless loop:
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';
}
}
}
It gets called from within this part of the function setSampPolicyElems() which you can see I've commented out to stop the loop:
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>");
}
To see the issue, go to the order review and submit page here:
https://checkout.netsuite.com/s.nl?c=659197&sc=4&n=1 (or go to http://www.avaline.com, hit "checkout", and login)
You can log in with these credentials:
Email : [email protected]
Pass : test03
My solution so far was to swap out the onchange() event trigger line with this, since then I'm not running document.location.href twice: instead, I'm passing the two variables in the one URL query string:
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的变量“i”是全局的。另外,您应该将 options.length 存储在变量中。
“i”可能由某些脚本设置,导致无限循环。
Your variable "i" is global. Also, you should store options.length in the variable.
"i" might be set by some scripts which cause infinite loop.
这是我的解决方案:
This was my solution: