我注意到彈出顯示在文本框中更新文本之前,我猜js在頁面呈現之前調用...這將解釋'未定義'彈出...我如何確保js在頁面呈現後被調用?
重寫,使其儘可能簡單:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtRcaNotes" runat="server" TextMode="MultiLine" Width="800px"></asp:TextBox><br />
<asp:Button ID="btnDoneWithRcs" runat="server" OnClick="btnDoneWithRcs_Click" Text="Action Completed/Update Notes" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(
function(){doStuff();}
);
function doStuff()
{
$(document).ready(function() {
$('txtRcaNotes').hide();
alert($('txtRcaNotes').attr('id'));
});
}
</script>
</body>
代碼背後:
TEXTBOX沒有得到隱藏的,ALERT()返回 '未定義'
alt text http://i41.tinypic.com/deyc14.jpg
哦,男人......我花了太多時間在這個... thanx :) – 2009-02-26 02:48:41