开发者

IE9 + Browser is not submitting the form in IE9, but works fine for IE7, IE8

开发者 https://www.devze.com 2023-04-12 17:30 出处:网络
In my Rails application, when i try to submit a form from 开发者_运维百科IE7 or IE8. It works as expected. But when I try from IE9, it fails.

In my Rails application, when i try to submit a form from 开发者_运维百科IE7 or IE8. It works as expected. But when I try from IE9, it fails.

How can I resolve this problem ?


Took me a little while to resolve this, but it's actually down to a bug in IE9 by the looks of it. If you have a <p> tag before your form, make sure you close it with </p> before you get to the <form> tag.

Basically, closing a <p> tag is optional, and it should be automatically closed by a block level element such as the <form> tag. Unfortunately IE9 is not closing it. However, if you then have a block level element in your form (such as a <div>), the <p> will automatically close at that point. The form then becomes a child element of the <p> tag, and the div element (along with your form controls and submit button) drops out of the form altogether.

This is bad:

<p> <form> <div> Form Contents </div> </form>

which is rendered in IE9 as:

<p> <form> </form> </p> <div> Form Contents </div>

This is good:

<p></p> <form> <div> Form Contents </div> </form>

I can only seem to replicate the problem when using scripting to modify the innerHTML, but as far as I understand this is a general bug with the <form> element within IE9. Personally, I would recommend closing ALL <p> tags manually to avoid any problems like this.

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消