iT邦幫忙

0

js/jquery 透過判斷form/string選擇開啟頁面

想請問有沒有什麼方式能讓button onclick後,透過form/string來判斷開啟哪個頁面呢?

我自己有試著用if else 但是只能成功開啟一個頁面,另外一個則會無法開啟(顯示無法存取你的檔案檔案可能已遭到移動、編輯或刪除。ERR_FILE_NOT_FOUND)

**InverterPrint/ColdPrint 後面的程式碼我沒有完整放上(公司的東西~

var cla = row.product_class;
var InverterPrint = '***.html';

var ColdPrint = '***.html';
    
    if (cla === "**") {
      window.open(InverterPrint, "_blank");
    }else{
      window.open(ColdPrint, "_blank");
    };
判斷就是你寫的這樣,提醒一下 if else 結尾不需要加分號
柯柯 iT邦新手 3 級 ‧ 2020-12-04 15:01:06 檢舉
如果是顯示你說的錯誤的話 先檢查路徑跟檔案 是否正確
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
qpalzm
iT邦新手 1 級 ‧ 2020-12-04 16:22:08

如果之後網頁多可以試試switch 有時候會比if else 效率好一點也比較好看~
會出現:另外一個則會無法開啟(顯示無法存取你的檔案檔案可能已遭到移動、編輯或刪除。ERR_FILE_NOT_FOUND)=>原因可能是你的網站名稱錯誤等等~~要先檢查檔案名稱。

let cla = row.product_class;
let InverterPrint = '';

    switch(cla){
    case "**":
        InverterPrint = '***.html';
    break;
    case "***":
        InverterPrint = '****.html';
    break;
    default:
     InverterPrint = '********.html';
    break;
    }
    window.open(InverterPrint, "_blank");

我要發表回答

立即登入回答