2015-06-20 56 views
1

我一直在使用document.write打開此鏈接,我正在新窗口中創建該鏈接。HTML創建一個包含按鈕的鏈接在新窗口中打開鏈接

document.write("<a target='blank' href='#"+link_number+"'>Click Here to open link</a>"); 

link_number是我創建的一個動態數字(每次都不一樣)。 現在我試圖把該鏈接到我的表是

<div id="tabs-10"> 
<table style="width:300px"> 
<tr><td><input type="button" id="Link1" checked /> Go to Link 1</td></tr> 
</table> 
</div> 

我知道如何創建一個按鈕,如 How to create an HTML button that acts like a link?

但我的問題是,我怎麼能轉換我的文件撰寫成我桌子上的一個按鈕?

謝謝 霍華德

回答

0

你的意思是這樣的嗎?

var addButton = function(text) { 
 
    var btn = document.createElement('button'); 
 
    var ttd = document.querySelectorAll('td')[0]; 
 

 
    btn.innerHTML = text; 
 

 
    ttd.appendChild(btn); 
 
} 
 

 
document.querySelectorAll('a')[0].onclick = function() { 
 
    addButton('Random ' + Math.random()); 
 
}
<div id="tabs-10"> 
 
    <table style="width:300px"> 
 
    <tr> 
 
     <td> 
 
     
 
     </td> 
 
    </tr> 
 
    </table> 
 
</div> 
 
<a>Add button</a>

相關問題