无法重置表单中的隐藏字段 [英] can't reset a hidden field in form

查看:130
本文介绍了无法重置表单中的隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中隐藏字段(初始值为0,而我的

javascript在触发事件时将其设置为1)。 />
在同一表格中,我有一个重置字段。但是当我按下

重置按钮时,我意识到隐藏的

字段没有重置为0。如果我只是从

"< input type =" hidden"更改节点id =''IsChanged''value =''0''>"

to

"< input type =" text" id =''IsChanged''value =''0''>"


一切都按预期工作(当我
按下重置按钮)为什么会发生这种情况?


谢谢

i have a form in which a hidden field (initial value as ''0'', and my
javascript set it to ''1'' when an event is trigged).
In the same form, i have a reset field. But I realized that the hidden
field is not reset to ''0'' when i push the
reset button. If I simply change the node from
"<input type="hidden" id=''IsChanged'' value=''0''>"
to
"<input type="text" id=''IsChanged'' value=''0''>"

Everything is working as expected (the value is reset to ''0'' when I
push the reset button) Why does this happen?

Thanks

推荐答案

新手在2007年8月12日下午5:26发表以下内容:
newbie said the following on 8/12/2007 5:26 PM:

i有一个隐藏字段的形式(初始值为'0) ''和我的

javascript在触发事件时将其设置为'1'。

在同一表格中,我有一个重置字段。但是当我按下

重置按钮时,我意识到隐藏的

字段没有重置为0。如果我只是从

"< input type =" hidden"更改节点id =''IsChanged''value =''0''>"

to

"< input type =" text" id =''IsChanged''value =''0''>"


一切都按预期工作(当我
按下重置按钮)为什么会这样?
i have a form in which a hidden field (initial value as ''0'', and my
javascript set it to ''1'' when an event is trigged).
In the same form, i have a reset field. But I realized that the hidden
field is not reset to ''0'' when i push the
reset button. If I simply change the node from
"<input type="hidden" id=''IsChanged'' value=''0''>"
to
"<input type="text" id=''IsChanged'' value=''0''>"

Everything is working as expected (the value is reset to ''0'' when I
push the reset button) Why does this happen?



Windows上的Safari和IE将其重置为0,Firefox和Opera不重置。所以我想b / b
我猜你正在用Firefox测试。为什么重置表单时不会重置

值,我不知道。我知道如果你输入

输入类型=" text"然后使用CSS使其隐藏,然后FF和

Opera将重置它:


< input type =" text"名称= QUOT; IsChanged"值= QUOT; 0" style =" display:hidden">


然后它是隐藏的通过CSS但Opera9,FF2.0,IE7和Safari / Win将

重置为0.


-

Randy

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


Evertjan。在2007年8月12日下午5:54发表以下内容:
Evertjan. said the following on 8/12/2007 5:54 PM:

newbie于2007年8月12日在comp.lang.javascript 中写道:
newbie wrote on 12 aug 2007 in comp.lang.javascript:

>我有一个隐藏字段的表单(初始值为''0'',而我的
javascript将其设置为''1 ''当一个事件被触发时)。
在同一个表格中,我有一个重置字段。但是当我按下
重置按钮时,我意识到隐藏的
字段没有重置为0。如果我只是从
"< input type =" hidden"更改节点id =''IsChanged''value =''0''>"
to
"< input type =" text" id =''IsChanged''value =''0''>"

一切都按预期工作(当我推动时,值会重置为'0''重置按钮)为什么会这样?
>i have a form in which a hidden field (initial value as ''0'', and my
javascript set it to ''1'' when an event is trigged).
In the same form, i have a reset field. But I realized that the hidden
field is not reset to ''0'' when i push the
reset button. If I simply change the node from
"<input type="hidden" id=''IsChanged'' value=''0''>"
to
"<input type="text" id=''IsChanged'' value=''0''>"

Everything is working as expected (the value is reset to ''0'' when I
push the reset button) Why does this happen?



< snip>

<snip>


在这里工作正常[IE7]
Works fine here [IE7]



在IE7和Safari3.0中正常工作,但在Firefox1.5 / 2.0和Opera9中都不行。


-

兰迪

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


RobG于2007年8月13日在comp.lang.javascript中写道
RobG wrote on 13 aug 2007 in comp.lang.javascript:

从逻辑上讲,我认为IE7和Safari3.0是错误的。

从技术上讲,这是一个规范问题。
I think IE7 and Safari3.0 are in error, logically speaking.
Technically it is a question of specification.


我个人认为IE7和Safari是对的。用户告诉浏览器
重置此表单这就是浏览器的功能。 FF和Opera不会做用户要求它做的事情。


Personally, I think IE7 and Safari are right. The user tells the browser
"Reset this form" and that is what the browser does. FF and Opera don''t
do what the user asked it to do.



我认为你是对的。


重置表单应该将所有值设置回初始值

,由HTML中的value属性设置。初始值是

存储在DOM defaultValue属性中,重置表单应该设置

所有控件都返回到defaultValue。


重置表单应该将所有控件设置回其defaultValue。

我没有看到以编程方式更改值的任何地方

属性应该更改隐藏控件的defaultValue属性
仅限



< URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-26091157 >


I think you''re right.

Resetting the form should set all values back to their initial value
which is set by the value attribute in the HTML. The initial value is
stored in the DOM defaultValue property, resetting the form should set
all controls back to the defaultValue.

Resetting a form should set all controls back to their defaultValue.
I don''t see anywhere that programmatically changing the value
attribute should change the defaultValue property for hidden controls
only:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-26091157 >



规范不一定符合逻辑,

为什么你要将隐藏字段称为控制?

我认为如果客户端js改变了一个隐藏字段,

那个js [程序员]的责任是重置它还是没有

检测到用户的行为:


< input type =''reset''

onclick =''return manipulateHiddenFieldsAsRequired(this);''> ;


顺便说一句,在js

管理表格中使用html重置按钮功能的整个想法通常不是最通用的解决方案,

特别是在跨浏览器环境中。

-

Evertjan。

荷兰。

(请将我的电子邮件地址中的x'变为点数)

Specification is not neccessarily logical and
why would you call a hidden field a "control"?

I think that if the clientside js altered a hidden field,
it is the responsability of that js [programmer] to reset it or not
after detecting the user''s actions:

<input type=''reset''
onclick=''return manipulateHiddenFieldsAsRequired(this);''>

btw, the whole idea of using the html reset button function in a js
governed form is often not the most versatile solution,
especially in a cross browser environment.
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于无法重置表单中的隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆