2017-04-07 71 views
0

我有一個輸入字段和一個按鈕。輸入字段在加載時有一個值,但是我想在加載頁面和點擊按鈕後將該值用作新選項卡中的URL來更改該值。我是JavaScript新手,任何輸入都會有所幫助。提前致謝。在新選項卡中打開輸入字段的值。我想實時更改輸入字段的值

<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td> 
    <input type="text" id="box" value="http://google.com" width="100%" /> 
</td> 
    <td> 
    <button id="newtab1" value = "Search" style="position: absolute;">New Tab</button> 
    </td> 
    </tr> 
</table> 
+0

如果你表現出什麼樣的代碼,你已經盡力了,我們可以幫你改善。 – freginold

+0

請閱讀[問]。重要短語:「搜索和研究」和「解釋......阻止你自己解決它的任何困難」。 –

回答

0

添加onclick屬性到您的按鈕。

<button id="newtab1" value = "Search" style="position: absolute;" onclick="MyFunction();">New Tab</button> 

然後讓你的函數過程輸入

<script> 
function MyFunction(){ 
    var url = document.getElementById('box').value 
    window.open(url); 
} 
</script> 
+0

什麼都沒有發生 – RittenRA

+0

我不得不改變console.log到window.open,它的工作原理...感謝一堆你的方向 – RittenRA

0
document.onload=function(){ 
var url ="your url " 
document.getElementById("box").value=url; 
} 
function myFunction(){ 
Window.open(document.getElementById("box"); 
} 
<button id="newtab1" value = "Search" style="position: absolute;" onclick="myFunction();">New Tab</button>