我需要通過javascript函數更改運輸承運人下拉和運輸方法單選按鈕,而不是永遠。JavaScript函數不會停止循環 - 它是在一個netsuite網站
然而,當我使用這個功能,它執行的審查時,當順序是< $ 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,點擊 「結算」,並登錄)
你可以用這些憑據登錄:
電子郵件:[email protected]
通行證: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;
這是可能的,我想。由於某種原因,它被列爲螢火蟲的全局變量,雖然我不知道它在哪裏被聲明,並且當我在for循環中使用'var i'時,我沒有遇到它的問題。... 爲什麼要將options.length存儲在一個變量中? – Lauren 2010-06-07 15:19:35