3 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
將<button>標(biāo)簽更改為<a>標(biāo)簽
按鈕沒(méi)有href和target屬性,<a>標(biāo)簽有。代碼應(yīng)該是這樣的:
function buildButton(url,i,size) {
document.write("Building Button with URL= "+url+"<p>");
var a = document.createElement("a");
a.appendChild(document.createTextNode("PIDs "+i+" to "+(i+size)));
a.setAttribute("href",url);
a.setAttribute("target","_blank");
document.body.appendChild(a);
}
buildButton('https://stackoverflow.com/', 1, 1);
<!DOCTYPE html>
<html>
<body>
</body>
</html>

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊
解決了它:
function buildButton(url,i,size) {
var btn = document.createElement("INPUT");
btn.setAttribute("type","button");
btn.setAttribute("onclick", "window.open('"+url+"')");
btn.setAttribute("value","PIDs "+i+" to "+(i+size));
btn.setAttribute("target","_blank");
document.body.appendChild(btn);
document.write("<p>");
}

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
另一個(gè)基于此HTML 按鈕在新選項(xiàng)卡中打開(kāi)鏈接的解決方案??雌饋?lái)你已經(jīng)想通了
function buildButton(url,i,size) {
document.write("Building Button with URL= "+url+"<p>");
var btn = document.createElement("button");
btn.appendChild(document.createTextNode("PIDs "+i+" to "+(i+size)));
btn.setAttribute("onclick","window.open('" +url+"', '_blank')");
document.body.appendChild(btn);
}
buildButton("http://www.google.com","Thing", 44) ;
添加回答
舉報(bào)