我有一个包含开始日期字段的Web表单。我把一个jquery的日期戳绑定到txt字段。现在,当我在FF中选择一个日期时,所选日期会填充在文本框中,并且日历弹出窗口关闭。但是,当我在IE8中做同样的事情时,选择的日期将填充在文本框中,但弹出窗口仍然打开。我也注意到,一旦在弹出日历中选择日期,就会生成脚本错误。
我正在使用jquery 1.3.2,jquery-ui 1.7.2和.NET 3.5。以下是我的代码示例:
<script type="text/javascript"> $(document).ready(function() { $("#<%=txtStartDate.ClientID%>").datepicker({ changeMonth: true,changeYear: true,showButtonPanel: true,showOn: 'button',buttonImage: '/_layouts/images/CALENDAR.GIF',buttonImageOnly: true }); }); </script> <div id="stylized"> <asp:ValidationSummary ID="vs" runat="server" CssClass="messages-error" HeaderText=" Action required before the form can be submitted." ForeColor="" ValidationGroup="sh" /> <div class="formrow"> <div class="ms-formlabel formlabel"> <asp:Label ID="lblStartDate" runat="server" CssClass="ms-standardheader" AssociatedControlID="txtStartDate">Start Date:</asp:Label> </div> <div class="ms-formbody formfield"> <asp:requiredFieldValidator ID="reqStartDate" runat="server" ControlToValidate="txtStartDate" ErrorMessage="Start Date is a required field." Text="*" Display="Dynamic" ValidationGroup="sh"></asp:requiredFieldValidator> <asp:CompareValidator ID="cvStartDate" runat="server" ControlToValidate="txtStartDate" ErrorMessage="Date must be in the format MM/DD/YYYY" Text="*" Display="Dynamic" ValidationGroup="sh" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator> <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox> <span class="formMessage">ex. MM/DD/YYYY</span> </div> </div> <div id="buttonrow"> <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="ms-ButtonHeightWidth" OnClick="Submit_Click" ValidationGroup="sh" /> <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="ms-ButtonHeightWidth" OnClick="Cancel_Click" CausesValidation="false" /> </div> </div>
当我选择日期时,我在IE中得到的脚本错误:
‘length’为null或不是一个对象
WebResource.axd的
function ValidatorOnChange(event) { if (!event) { event = window.event; } Page_InvalidControlToBeFocused = null; var targetedControl; if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null)) { targetedControl = event.srcElement; } else { targetedControl = event.target; } var vals; if (typeof(targetedControl.Validators) != "undefined") { vals = targetedControl.Validators; } else { if (targetedControl.tagName.toLowerCase() == "label") { targetedControl = document.getElementById(targetedControl.htmlFor); vals = targetedControl.Validators; } } var i; for (i = 0; i < vals.length; i++) { ValidatorValidate(vals[i],null,event); } ValidatorUpdateIsValid(); }
它发生在最后的for循环的.length上。 Vals为空,在前一个if / else中找不到。我已经通过javascript和if(typeof(targetedControl.Validators)!=“undefined”)返回false,然后if(targetedControl.tagName.toLowerCase()==“label”)也返回false。因此,长度为null或不是对象错误。
现在我不知道如果datepicker弹出窗口没有关闭在IE和WebResources.axd文件中的脚本错误是相关的错误,但我倾斜这样。任何人都可以告诉我为什么弹出窗口没有关闭?