我找到了類似的答案,但不完全是我想要的。如何處理具有 1 個功能的 3 個按鈕?如何將檔案屬性集成到解決方案中?
這是代碼:
function gotoUrl() {
window.location.assign("https://www.google.com/")
}
function gotoUrl1() {
window.location.assign("https://www.yahoo.com/")
}
function gotoUrl2() {
window.location.assign("https://www.youtube.com/")
}
<button class="one" onclick="gotoUrl()"> Google </button>
<button class="two" onclick="gotoUrl1()"> yahoo </button>
<button class="three" onclick="gotoUrl2()"> Youtube </button>
uj5u.com熱心網友回復:
你可以進入params一個函式,它是一個函式在運行時包含在其中的變數。這是您僅使用 1 個函式修改的代碼:
<!-- html -->
<button class="one" onclick="gotoUrl('https://www.google.com')"> Google </button>
<button class="two" onclick="gotoUrl('https://www.yahoo.com')"> yahoo </button>
<button class="three" onclick="gotoUrl('https://www.youtube.com')"> Youtube </button>
// javascript
function gotoUrl(link /*link is a param, now we can use it as a variable in our function*/){
window.location.assign(link)
}
w3schools 上的引數:https : //www.w3schools.com/js/js_function_parameters.asp
uj5u.com熱心網友回復:
function gotoUrl() {
window.open("https://www.google.com/")
}
function gotoUrl1() {
window.open("https://www.yahoo.com/")
}
function gotoUrl2() {
window.open("https://www.youtube.com/")
}
<button class="one" target="_blank" onclick="gotoUrl()"> Google </button>
<button class="two" target="_blank" onclick="gotoUrl1()"> yahoo </button>
<button class="three" target="_blank" onclick="gotoUrl2()"> Youtub </button>
open() 方法根據您的瀏覽器設定和引數值打開一個新的瀏覽器視窗或一個新選項卡。
句法:
window.open(URL, name, specs, replace)
更多詳情請點擊:window.open
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/341326.html
標籤:javascript 按钮 窗口位置
下一篇:如何在反應中從孩子執行父操作
