我沒有 JS 經驗,但我需要幫助。
所以我有一個允許用戶手動輸入 URL 的代碼。
好吧,如果他們將該值留空并單擊“NULLS”。我想要一種方法來檢測 null 并恢復到“/”或相同的頁面而不是 /null
function url(){
swal("Enter a URL:", {
content: "input",
})
.then((value) => {
location.replace(value);
});
}
// PROD Fix, needs a zero-null failure-fix. Find a way to prevent zero-data/null.
uj5u.com熱心網友回復:
您可以在 location.replace() 之前為空值添加一個測驗,并將該值更改為您想要的默認 url。
function url(){
swal("Enter a URL:", {
content: "input",
})
.then((value) => {
if (value === null) value = "your replacement url";
location.replace(value);
});
}
uj5u.com熱心網友回復:
仔細檢查if (value === null)您是否可以收到 null 或空字串。如果您收到空字串,則條件將失敗。
我會用它if (!value)來覆寫 null && ""。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/379266.html
標籤:javascript
