簡體   English   中英

設置html輸入或textarea的值

[英]set value of html input or textarea

這是完美的工作。 我想獲取當前URL並將其設置在textarea或輸入標簽內。 實際上,該值設置為p標簽。

 function urlf() { document.getElementById("root").innerHTML = "The full URL of this page is: < br > " + window.location.href; } 
 <h2>JavaScript</h2> <h3>The window.location.href</h3> <button id="my btn" type="button" onclick="urlf()"> get </button> <p id="root"> </p> 

我怎樣才能做到這一點?

創建一個input標簽並設置其value

 function urlf() { document.getElementById("root").value = "The full URL of this page is:" + window.location.href; } 
 <h2>JavaScript</h2> <h3>The window.location.href</h3> <button id="my btn" type="button" onclick="urlf()"> get </button> <input type="text" style="width:100%;" id="root"> 

您可以使用id root設置元素的innerHTML 根據您的代碼,這是:

<p id="root"> </p>

因此,如果要將內容加載到輸入字段中,則需要更改以下內容:

 document.getElementById("root").value = "The full URL of this page is:" + window.location.href; 
 <input id="root" type="text" /> 

問候

您只需要輸入當前的URL? 如下所示:

  function urlf() { document.getElementById("root").value = "The full URL of this page is:" + window.location.href; } 
 <div> <h2>JavaScript</h2> <h3>The window.location.href</h3> <button id="my btn" type="button" onclick="urlf()"> get </button> <input style="width:500px;" type="text" id="root"/> </div> 

<input id="root" type="text">

function urlf() {
    document.getElementById("root").value = window.location.href;

}

是否可以設置 a 的 value 屬性<textarea><i>tag to be the source code of an html file?</div></i><b>標記為 html 文件的源代碼?</div></b></textarea><div id="text_translate"><p> 我想知道是否可以將 <textarea> 標記的值屬性設置為網頁的 HTML。</p><p> 我試圖將值設置為等於本地文件“./file.html”的 HTML。</p><pre> document.getElementById("textareaTag").value =;</pre><p> 由於我是 JavaScript 的新手,所以我沒有解決方案,盡管可能有一個。 誰能幫我?</p><p> 注意:一些挖掘使得它看起來可能使用 window.open() 命令來完成此操作。 行得通嗎? 如果是這樣,如何?</p></div>

[英]Is it possible to set the value property of a <textarea> tag to be the source code of an html file?

暫無
暫無

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

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