输入隐藏和innerHTML的奇怪问题
我有一个带有一些文本的文本区域。我还有一个“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试将
innerHTML
与文本区域一起使用是否有原因?只需使用value
属性,即可获取文本区域中的任何文本。Is there a reason you're trying to use
innerHTML
with the textarea? Just use thevalue
property, which will get you whatever text is in the textarea.尝试:
虽然我不明白为什么你不直接使用文本区域的内容(命名它并与表单一起提交)。文本区域的
value
是您实际想要显示的内容,这不是innerHTML
的正确位置。Try:
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 forinnerHTML
.