如何在 IE 中的 HTML 中设置输入标记的内部值

发布于 2024-12-17 06:05:14 字数 397 浏览 3 评论 0原文

我正在尝试在 IE 中动态设置值标签的innerHTML。

我期望的输出是这样的。

<input type="hidden" >a0FQ0000009rJfCMAU</input>

我在 IE 中尝试了innerHTML,但它不起作用,因为它支持 INPUT 元素。于是,我在绝望中尝试了以下方法。

myElementId.setAttribute("value",textNodeId);

不幸的是这不是我想要的。

<input type="hidden" value="a0FQ0000009rJfCMAU">

请指教。

I am trying to set dynamically innerHTML for value tag in IE.

The output I expect is this.

<input type="hidden" >a0FQ0000009rJfCMAU</input>

I tried innerHTML in IE but it was not working since it is supported for INPUT element. So, I tried the following out of desperation.

myElementId.setAttribute("value",textNodeId);

Unfortunately this is not what I want.

<input type="hidden" value="a0FQ0000009rJfCMAU">

Please advise.

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

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

发布评论

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

评论(2

笨死的猪 2024-12-24 06:05:14

如果您检查 input 元素的规范,您会发现其内容模型 应为空。因此,您尝试查找的是逻辑上无效的 HTML。

请参阅此处

If you check the input element's specification, you see that its Content Model should be empty. Thus, what you try to find is logically invalid HTML.

See here.

深海夜未眠 2024-12-24 06:05:14

如果你想动态更改或设置输入标签的值,你必须首先定义它的名称或id,然后在javascript中你可以设置它,就像

var txt = document.getElementById('yourtext');
txt.value = 'new value';

我希望这对你有帮助。

If you want to change or set the value of input tag dynamically, you have to first define its name or id and then in javascript you can set it like

var txt = document.getElementById('yourtext');
txt.value = 'new value';

I hope this helps you.

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