本文介绍了Textarea值不出现在$ _POST对象上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 伙计们,我会在这个问题上挠头。 我有这个网站,它基本上包含一些表格由用户填写。然后,用户可以以可读的格式(pdf)或机器可读的格式(xml)下载这些信息,但我在提交文本框时遇到了一些问题。 我有一个其中很少,例如在描述部分,但是当我访问$ _POST ['Desc_Desc_desc']值时,即使我可以在textarea上看到内容,它也是空的。奇怪的是,当我使用萤火虫检查元素时,它显示元素就好像它没有内容。 任何人都可以判断是什么导致了这种奇怪的行为?解决方案在 service_level_library.buttons.prepForSubmit 中,textarea被克隆以及通过DOM cloneNode 方法。这会复制HTML元素属性,但不会复制DOM属性。 (有时,DOM元素节点属性的相应的属性,因此更新属性会影响属性,这可能会使DOM属性被复制。) 虽然 textarea DOM对象有一个 value 属性, textarea HTML元素不会具有相应的值属性,因此值属性不会公开属性。因此,当你克隆节点时,(空的)值属性被复制,留下当前值(可通过值 要修复脚本,请执行以下任一操作: li>克隆后复制值。 设置初始值,在克隆之前设置节点的文本内容或设置节点的文本内容。这是有效的,因为克隆节点的当前值将被设置为其初始值,并且textarea的深层副本将复制其文本内容(其初始值的源)。 在编程前用编程方式替换文本区域(尽管这会比其他选项更为复杂)Guys, im scratching my head around this one.I have this website that basically contains a few forms that are filled in by the user. The user then can download that information in human readable format (pdf) or machine readable format (xml) but I'm having a slight problem submitting textboxes.I have a few of them, for instance in the description section, but when i access the $_POST['Desc_Desc_desc'] value, it's empty even though i can see content on the textarea. The weird thing is that when i use firebug to inspect the element, it shows the element as if it had no contents..Can anyone figure what is causing this strange behavior? 解决方案 In service_level_library.buttons.prepForSubmit, the textarea is cloned along with the rest of the form via the DOM cloneNode method. This copies HTML element attributes, but not DOM properties. (Sometimes DOM element node properties have a corresponding attribute, so updating the property affects the attribute, which can make it appear that DOM properties are being copied.)While textarea DOM objects have a value property, the textarea HTML element doesn't have a corresponding value attribute, so the value property isn't exposing an attribute. Thus when you clone the node, the (empty) value attribute is what gets copied, leaving the current value of the element (as accessible via the value property) behind.To fix your script, do one of:Copy the value after cloning.Set the initial value for the textarea, either by assigning to the defaultValue property or setting the text content of the node, before cloning. This works because the current value of the cloned node will be set to its initial value, and a deep copy of a textarea will copy its text contents (the source of its initial value).Programmatically replace the textarea with an input before cloning (though this would be more involved than the other options), 这篇关于Textarea值不出现在$ _POST对象上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 12:36