Jquery 字符限制在更新面板内不起作用

Jquery 字符限制在更新面板内不起作用,jquery,asp.net,updatepanel,limit,Jquery,Asp.net,Updatepanel,Limit,我使用的Jquery插件如下所示 相关ASPX部分 <td align="left" valign="top"> <textarea id="Textarea1" class ="limit" runat="server" rows="4" cols="30" style="resize: none; background-color: #F9E8EC; font-family: 'Times New Roman', Times, serif;" >

我使用的Jquery插件如下所示

相关ASPX部分

<td align="left" valign="top">
    <textarea id="Textarea1" class ="limit" runat="server" rows="4" cols="30" style="resize: none;
        background-color: #F9E8EC; font-family: 'Times New Roman', Times, serif;" ></textarea>
    <br />
    You have <span id="charsLeft">160</span> chars left.
</td>


你还有160个字符。

以上两个控件都位于更新面板内。我第一次看到这个极限函数工作得很好。但当更新面板更新跨度显示160个字符,并没有更新时,在文本区域键入。如何解决此问题?

我认为您必须将span留空。jQuery插件将自己填充它。

Damith我尝试了你的代码,它对我来说完全正常。你有什么错误吗

下面是我正在使用的HTML代码,JavaScript与您的相同

<form id="form1" runat="server">
 <asp:ScriptManager runat="server" />
 <asp:UpdatePanel ID="upd1" runat="server">
   <ContentTemplate>    
     <textarea id="Textarea1" class ="limit" runat="server" rows="4" cols="30"      style="resize: none; background-color: #F9E8EC; font-family: 'Times New Roman', Times, serif;" ></textarea>
<br />
 You have <span id="charsLeft">160</span> chars left.
<asp:Button ID="btnTest" runat="server" Text="Test" />
</ContentTemplate>


你还有160个字符。


我希望有帮助

问题在于更新面板和
文档
准备就绪
玩得不好。更新面板基本上会替换页面上的所有内容,但由于
文档
已准备就绪,因此事件不会重新触发

您要做的是将
文档
就绪
事件移动到一个单独的函数中,然后在文档就绪期间和更新面板中发生更新时调用它,如下所示:

function onDocumentReady()
{
    $('[id$=Textarea1]').limit('150', '#charsLeft');
}

// this will get called on the first load
$(function()
{
    onDocumentReady();
});

// this will get called when an update panel request finishes
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance(); 
pageRequestManager.add_endRequest(onDocumentReady);
或者(未经测试) 当更新面板重新加载时,您可能会触发
文档上的
ready
事件,您可以尝试以下操作:

// this will get called on the first load
$(function()
{
    $('[id$=Textarea1]').limit('150', '#charsLeft');
});

// this will get called when an update panel request finishes, triggering the dom ready
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance(); 
pageRequestManager.add_endRequest(function()
{
    $(document).trigger('ready');
});

如果我将空白范围设置为空,则在更新面板刷新时显示为空。@Nil,感谢您提供的信息,没有错误,但它不起作用。。bdw我的aspx更复杂,我使用Chrome作为浏览器。借助理查德的回答,我能够解决这个问题
// this will get called on the first load
$(function()
{
    $('[id$=Textarea1]').limit('150', '#charsLeft');
});

// this will get called when an update panel request finishes, triggering the dom ready
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance(); 
pageRequestManager.add_endRequest(function()
{
    $(document).trigger('ready');
});