我有一个输入字段和一个按钮。输入字段在加载时具有值,但我想在页面加载后更改该值,并在单击按钮时将值用作新选项卡中的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 :(得分: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>
答案 1 :(得分: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>