输入隐藏和innerHTML的奇怪问题

发布于 2024-09-27 08:07:21 字数 375 浏览 1 评论 0原文

我有一个带有一些文本的文本区域。我还有一个“onsubmit”事件处理程序。我收到了文本区域的 insideHTML 警报,并取回了文本区域内的文本。然后,我尝试将其分配给隐藏输入元素的“value”属性。然而,该值从未被分配,当表单发布时,隐藏元素没有值。

我什至尝试过这样的

hiddenElement.value = "please work " + textarea.innerHTML;

这也不起作用,但是当我这样做并提交表单时,表单处理程序 ( jsp 页面)显示“please work”已作为隐藏输入被接收。

我还检查了 firebug,隐藏元素只提交“请工作”,而不是文本区域的innerHTML。

我缺少什么?

I have a text area with some text. I also have an "onsubmit" event handler. In that I have an alert of the text area's innerHTML and I get back the text that is inside of the textarea. I then try to assign this to the "value" attribute of a hidden input element. However the value is never assigned, when the form posts, the hidden element has no value.

I've even tried something like this

hiddenElement.value = "please work " + textarea.innerHTML;

and that doesn't work either, however when I do this and submit the form, the form handler (a jsp page) shows that "please work" was received as the hidden input.

I've also checked firebug and the hidden element only ever submits "please work" and not the innerHTML of the text area.

What am I missing?

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

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

发布评论

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

评论(2

很糊涂小朋友 2024-10-04 08:07:21

您尝试将 innerHTML 与文本区域一起使用是否有原因?只需使用 value 属性,即可获取文本区域中的任何文本。

Is there a reason you're trying to use innerHTML with the textarea? Just use the value property, which will get you whatever text is in the textarea.

浮世清欢 2024-10-04 08:07:21

尝试:

hiddenElement.value = "please work " + textarea.value;

虽然我不明白为什么你不直接使用文本区域的内容(命名它并与表单一起提交)。文本区域的 value 是您实际想要显示的内容,这不是 innerHTML 的正确位置。

Try:

hiddenElement.value = "please work " + textarea.value;

Although why you wouldn't just use the content of the textarea directly (name it and submit it with the form) is beyond me. The value of a textarea is what you actually want to display, this isn't the right place for innerHTML.

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