【问题标题】:javascript function won't stop looping - It's on a netsuite websitejavascript函数不会停止循环 - 它在netsuite网站上
【发布时间】:2010-06-04 15:54:00
【问题描述】:

我需要通过 javascript 函数更改一次运输承运人下拉菜单和运输方式单选按钮,而不是永远。

但是,当我使用此功能时,当订单

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;

【问题讨论】:

    标签: javascript function loops refresh netsuite


    【解决方案1】:

    您的变量“i”是全局变量。此外,您应该将 options.length 存储在变量中。 "i" 可能由某些导致无限循环的脚本设置。

    【讨论】:

    • 我想有可能。出于某种原因,它在 firebug 中被列为全局变量,虽然我不知道它是在哪里声明的,而且我之前在 for 循环中使用 'var i' 时没有遇到问题......为什么将 options.length 存储在变量中?
    【解决方案2】:

    这是我的解决方案:

    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;
    

    【讨论】:

      猜你喜欢
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多