javascript 函数不会停止循环 - 它位于 netsuite 网站上

发布于 2024-09-03 20:55:33 字数 2219 浏览 6 评论 0原文

我需要通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半世晨晓 2024-09-10 20:55:33

你的变量“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.

花辞树 2024-09-10 20:55:33

这是我的解决方案:

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;

This was my solution:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文