2017-04-07 74 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>