![](/img/trans.png)
[英]How do I copy text from an <Input> by using getElementbyTagName?
[英]How can I copy text from input
我用翻譯寫作。
我希望輸入文本出現在段落中,然后單擊按鈕。
html 代碼:
<input id="demo">
<button onclick="myFunction()">Click me</button>
<p id="test"></p>
JS代碼:
var txt = JSON.parse(demo);
function myFunction() {
var txt = JSON.parse(demo); function myFunction() { document.getElementById("test").innerHTML = txt; }
<input id="demo"> <button onclick="myFunction()">Click me</button> <p id="test"></p>
您需要在 function 中獲取輸入的值。 無需使用JSON.parse
。
function myFunction() { document.getElementById("test").innerHTML = document.getElementById("demo").value; }
<input id="demo"> <button onclick="myFunction()">Click me</button> <p id="test"></p>
function copyToParagraph() { var inputValue = document.getElementById('txtInput').value; var paragraphEle = document.getElementById('par'); paragraphEle.innerHTML = inputValue; console.log(inputValue); console.log(paragraphEle); }
<input type="text" id="txtInput" /> <br/> <button onclick="copyToParagraph()">Click Me to Copy</button> <br/><br/><br/> <p id="par"></p>
你需要做一個var input = document.getElementById('input').value;
讓你擁有價值。 然后這樣做:
function myFunction() {
var input = document.getElementById('input').value;
document.getElementById('demo').innerHTML = input;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.