English 中文(简体)
$.slideDown()后消失<textarea>
原标题:Disappearing <textarea> after $.slideDown()

我在IE7及以下版本中遇到了一个问题,我正在通过$.slideUp()&$.slideDown(),有一个正在消失的文本区域。

这是表单代码:

<% using (Html.BeginForm("AddComment", "Comment", FormMethod.Post, new { id = "addCommentForm", @class = "comments-form" }))
 { %>
    <input type="hidden" name="SiteID" value="<%: Model.Name %>" />
    <table>
        <colgroup>
            <col class="comments-form-text" />
            <col class="comments-form-submit" />
        </colgroup>
        <tbody>
            <tr>
                <td>
                    <textarea name="Text" rows="2" cols="75"></textarea>
                </td>
                <td>
                    <div>
                        <input type="submit" value="Add Comment" />
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
    <% } %>

我用javascript(使用jQuery)中的按钮点击切换显示:<code>$(#addCommentForm).slideDown()

我的问题是,在IE7及以下版本中,当表单完成向下滑动时,文本区域就会消失。只有当我浏览了提交按钮(它是使用jQueryUI<code>.button()</code>方法设计的)时,它才会再次出现。

当我说消失的时候,它就消失了。看看IE开发工具中的html,它的html仍然存在,只是根本没有被渲染。

尽管我非常讨厌IE,但我必须支持它:(

有人知道为什么会发生这种事吗?或者我该如何缓解?

最佳回答

有一些方法可以解决这个问题:

  • Try using another element, like a span instead of a div element to slideDown. Might be an IE s rendering bug;
  • Another approach, is to set zoom:1; in your CSS to the element you re trying to slideDown;
  • You can also solve this setting a min-height to your sliding element in your CSS;
问题回答

在元素上设置宽度可以解决问题。所有@paullilo解决方案都运行良好,但设置宽度将有助于保护您免受其他相关错误的影响。

slideDown将位置临时设置为绝对,这有时会产生一个称为“跳跃”错误的错误。发生这种情况的原因是,当元素宽度在其绝对值的短暂时刻发生变化时,有时slideDown无法准确计算高度。除非迫不得已,否则我讨厌设置宽度,但在这种情况下,如果可以的话,我建议您这样做。





相关问题
Image rendered with wrong colors in IE8

I have a gradient image as a PNG (no transparency) in a web-page. By taking a screenshot of Chrome showing the page and cropping the image from the page, I see the exact same colors are drawn as the ...

Determine Mobile Internet Explorer version

I need to determine the version of Mobile Internet Explorer on a Windows Mobile 6.1 device. So that I can report the same user-agent string as is being used by Mobile Internet Explorer. The user-...

CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

Internet Explorer only part loading JavaScript/CSS

I m having trouble with my local development environment where IE (6 through to 8) is only part loading JavaScript/CSS files. It throws random errors at random places in jquery.min.js every time I ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签