javascript函数不会停止循环-它在netsuite网站上
我需要通过javascript函数更改shipping carrier下拉列表和shipping method单选按钮一次,而不是永远 但是,当我使用此功能时(当订单<5美元时在“审阅和提交”页面上执行),它会进入一个无休止的循环:javascript函数不会停止循环-它在netsuite网站上,javascript,function,loops,refresh,netsuite,Javascript,Function,Loops,Refresh,Netsuite,我需要通过javascript函数更改shipping carrier下拉列表和shipping method单选按钮一次,而不是永远 但是,当我使用此功能时(当订单
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';
}
}
}
你的变量i是全局的。此外,还应在变量中存储options.length。 我可能被一些导致无限循环的脚本设置。这是我的解决方案:
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;
我想这是可能的。出于某种原因,它被列为firebug中的一个全局变量,尽管我不知道它是在哪里声明的,而且我以前在循环中使用“var I”时没有遇到问题。。。。为什么要将options.length存储在变量中?
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;
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;