是否可以设置a< textarea>标签是HTML文件的源代码?

发布于 2025-01-18 03:13:56 字数 275 浏览 2 评论 0原文

我想知道是否可以设置a< textarea>标签要设置为网页的HTML。

我试图将值设置为等于本地文件的HTML“ ./file.html”。

document.getElementById("textareaTag").value = ;

由于我是JavaScript的新手,因此我没有解决方案,即使可能有一个。谁能帮我吗?

注意:有些人四处挖掘会使使用window.open()命令完成此操作。它可以工作吗?如果是这样,怎么样?

I want to know if it is possible to set the value property of a <textarea> tag to be set to the HTML of a webpage.

I'm trying to set the value to be equal to the HTML of the local file "./file.html".

document.getElementById("textareaTag").value = ;

Since I'm new to JavaScript, I don't have a solution, even though there probably is one. Can anyone help me?

NOTE: Some digging around makes it look like it might be possible to accomplish this with a window.open() command. Would it work? If so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2025-01-25 03:13:56

您可以通过此方法将HTML文件放入JS变量:

加载页面内容到变量

,然后将变量放入TextAarea中。
尽管在Textarea中,您无法显示HTML标签,并且需要像Ckeditor这样的Wysiwyg富文本编辑器。

You can place an HTML file into a JS variable by this method:

Load page content to variable

And then put variable into textarea.
Although in textarea you can't show html tags and you need a WYSIWYG rich text editor like CKEditor.

淑女气质 2025-01-25 03:13:56

我不确定我是否理解您的问题,但我会尽力回答。

您可以使用

使用以下代码:

document.querySelector("textarea").innerHTML = "Textarea!";

编辑:在不同网页上编辑文本存在安全风险。

I'm not sure if I understand your question, but I'll try my best to answer.

You can set the text inside of a <textarea> using the .innerHTML property, as the textarea tag has an opening and closing tag.

Use the code below:

document.querySelector("textarea").innerHTML = "Textarea!";

EDIT: Editing the text on a different webpage is a security risk.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文