在Internet Explorer 9中,HTML表单默认值会覆盖发布时间的实际值 [英] HTML form default values override actual values at post time in Internet Explorer 9

查看:175
本文介绍了在Internet Explorer 9中,HTML表单默认值会覆盖发布时间的实际值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在我的网站上测试全新的Internet Explorer 9 Beta。我看到了一些表单值的奇怪行为,我不确定这是我的错误还是IE9中的错误。你有什么感想?



我有一个表单声明了几个隐藏的输入字段,像这样

 < input type =hiddenname =NewStatus/> 
< input type =hiddenname =lastSaveStatusvalue =/>

提交页面时,值将以这种方式保存(使用JavaScript):

  newStatus.setAttribute(value,myNewStatus); 
var formLastStatus = document.getElementsByName(lastSaveStatus)[0];
formLastStatus.setAttribute(value,lastSaveStatus);
alert(lastSaveStatus);
alert(formLastStatus.getAttribute(value));
var form = document.getElementById(myForm);
form.submit();

该代码已经在所有浏览器中运行了数年。
这些警报已经表明我现在遇到lastSaveStatus字段存在问题。
在IE9中,NewStatus被正确地传送到服务器(意味着我可以使用Request.Form [NewStatus]访问ASP.NET中的值)。
但lastSaveStatus的值总是。

正如你所看到的,我在我的隐藏字段的定义中使用了一个值=。如果我删除此默认值,则新值将正确传输到服务器。如果我使用默认值,则始终会传输默认值。



任何想法为什么会发生这种情况?

解决方案

你确定这工作在以前的版本的IE?我在IE / Win中总是遇到这样的语法问题,下面的代码应该可以工作:

  formLastStatus.value = lastSaveStatus; 

以上内容也适用于所有浏览器。


I am just testing the brand new Internet Explorer 9 Beta with my website. I see a weird behaviour for some form values and I am not sure if it is my mistake or a bug in IE9. What do you think?

I have one form which declares several hidden input fields like this

<input type="hidden" name="NewStatus" />
<input type="hidden" name="lastSaveStatus" value="" />

When the page is being submitted, the values are saved like this (in JavaScript):

newStatus.setAttribute("value", myNewStatus);
var formLastStatus = document.getElementsByName("lastSaveStatus")[0];
formLastStatus.setAttribute("value", lastSaveStatus);
alert(lastSaveStatus);
alert(formLastStatus.getAttribute("value"));
var form = document.getElementById("myForm"); 
form.submit();

That code has worked for years and across all browsers. The alerts already indicate that I have now a problem with the lastSaveStatus field. In IE9 the NewStatus is correctly transmitted to the server (means that I can access the value in ASP.NET using Request.Form["NewStatus"]). But the value for "lastSaveStatus" is always "".

As you can see I used a value="" in the definition of my hidden field. If I remove this default value, the new value is correctly transferred to the server. If I use a default value, always the default value is transferred.

Any idea why this is happening?

解决方案

Are you sure this worked in previous versions of IE? I've always had problems with that syntax in IE/Win, the following should work however:

formLastStatus.value = lastSaveStatus;

The above should work in all browsers, too.

这篇关于在Internet Explorer 9中,HTML表单默认值会覆盖发布时间的实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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