繁体   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