【问题标题】:IE8 cursor jumps to the end of a textarea when an UpdatePanel fires当 UpdatePanel 触发时,IE8 光标跳到文本区域的末尾
【发布时间】:2011-08-17 01:47:04
【问题描述】:

我在这样的页面上有一个 UpdatePanel 和一个文本区域:

<asp:Timer runat="server" ID="Timer" Interval="1000" OnTick="Tick" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
    <ContentTemplate>
        <asp:Label ID="Label" runat="server" />          
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="Timer" eventname="Tick" />
    </Triggers>
</asp:UpdatePanel>

<asp:TextBox runat="server" Width="600" Height="400" TextMode="MultiLine" />

// Codebehind
protected void Tick(object sender, EventArgs e) {
    Label.Text = DateTime.Now.ToString();
}

每当 UpdatePanel 计时器触发时,文本区域中的光标就会移动到文本的末尾。如果您尝试将任何文本添加到文本区域的中间,则由于光标一直跳到末尾,这将变得非常困难。这发生在IE8中。所有其他浏览器都非常乐意让您在文本的中间键入 而不会出现问题。

知道为什么会在 IE 中发生这种情况以及如何阻止它吗?

【问题讨论】:

    标签: c# asp.net internet-explorer-8 updatepanel textarea


    【解决方案1】:

    我相信 IE8 有一个已知的文本区域错误。

    尝试将最小宽度和最大宽度设置为相同的值。

    只是为了确保,如果您使用兼容模式,是否会发生此错误?

    textarea {
      width: 700px;
      min-width: 100%;
      max-width: 100%;
    }
    

    您可能还想设置一个固定像素height 属性。

    【讨论】:

    • 这是在兼容模式下发生的,宽度、高度和最小/最大宽度都已设置。它也发生在 IE7、IE8 和 quirks 模式中。
    • 这个问题和这里的页面不一样:grantovich.net/misc/ie8-textarea-bug。无论您是否在框中输入,都会发生这种情况。只需将光标放在框中的任意位置并等待 ajax 计时器即可将光标踢到末尾。
    猜你喜欢
    • 1970-01-01
    • 2011-10-17
    • 2012-04-26
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    相关资源
    最近更新 更多