多個頁面共用一個子視窗檢索時,若要回傳的資料數不同時,且某個頁面又沒有回傳的欄位名稱,該回傳敘述之後的程式片斷就不會執行。
function c1(a,b,c,d,e,f){
window.opener.document.getElementById("ss1_no").value =a;
window.opener.document.getElementById("ss1_order_no").value =b;
window.opener.document.getElementById("ss1_cum").value =c;
window.opener.document.getElementById("ss1_item").value =d;
window.opener.document.getElementById("ss1_type").value =e;<=這個欄位只有某個頁面有
window.opener.document.getElementById("ss1_pack").value =f;<=這個欄位只有某個頁面有
window.close();}
我的解決流程如下:
1.當程式編譯錯誤的時候一定會有回傳值,所以我試著找出當javascript找不到某個網頁元件時會出現什麼訊息。
2.將不存在的元件做輸出的動作,alert(window.opener.document.getElementById("ss1_type"));
3.結果傳回了一個很漂亮的值 『null』。
4.解決方式:
function c1(a,b,c,d,e,f){
window.opener.document.getElementById("ss1_no").value =a;
window.opener.document.getElementById("ss1_order_no").value =b;
window.opener.document.getElementById("ss1_cum").value =c;
window.opener.document.getElementById("ss1_item").value =d;
if (window.opener.document.getElementById("ss1_type")!=null){
window.opener.document.getElementById("ss1_type").value =e;
window.opener.document.getElementById("ss1_pack").value =f;
}
window.close();}
多個if判斷問題就解決了…
ps:這個問題一般人碰不到,就算碰到了google大師也不跟你講答案…
遇到問題時常常會有一定的解決程序,所以學會解決問題的方法比找到答案更有用。
留言列表