簡體   English   中英

在新標簽頁中打開輸入字段的值。 我想實時更改輸入字段的值

[英]open the value of an input field in new tab. I would like to change the value of the input field in real time

我有一個輸入字段和一個按鈕。 輸入字段在加載時有一個值,但是我想在頁面加載后更改該值,然后在按鈕上單擊將其用作新選項卡中的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>

將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>
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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM