简体   繁体   English

jQuery没有在IE10中触发

[英]jQuery not firing in IE10

$(document).ready(function () {
    $('#ctl00_ContentPlaceHolder1_btnDisplayReport').click(function () {
        if ((new Date($('#ctl00_ContentPlaceHolder1_txtStartDateFrom').val()) > new Date($('#ctl00_ContentPlaceHolder1_txtStartDateTo').val())) && $('#ctl00_ContentPlaceHolder1_txtStartDateTo').val() != "") {
            alert("Start date cannot be greater than end date.");
            return false;
        }

        if (new Date(($('#ctl00_ContentPlaceHolder1_txtCompletionDateFrom').val()) > new Date($('#ctl00_ContentPlaceHolder1_txtCompletionDateTo').val())) && $('#ctl00_ContentPlaceHolder1_txtCompletionDateTo').val() != "") {
            alert("Completion start date cannot be greater than completion end date.");
            return false;
        }
    });

    $('.dateverification>input').each(function () {
        $(this).change(function () {
            temp = $(this).attr("id");
            temp = temp.replace("txt", "lbl");
            if ($(this).val()) {
                $('#' + temp).show();
            }
        });

        $('.xlink').click(function () {
            temp1 = $(this).attr("id");
            temp1 = temp1.replace("lbl", "txt");
            $('#' + temp1).val("");
            temp1 = temp1.replace("txt", "lbl");
            $('#' + temp1).hide();
        });
    });
});

This is e jQuery function which works perfectly in FF and Chrome, but not firing in IE10, and the part that is not working starts from $('.dateverification>input').each(function()... I don't catch any javascript errors with dev tools or something I should be aware of. Basically, I am missing something and I can't get it work for all browsers. (Also did a no-cache request in my codefile) 这是e jQuery函数,它在FF和Chrome中完美运行,但不在IE10中触发,而不工作的部分从$('.dateverification>input').each(function()...我不使用开发工具或我应该注意的东西捕获任何javascript错误。基本上,我遗漏了一些东西,我无法让它适用于所有浏览器。(我的代码文件中也没有缓存请求)

<tr>
    <td style="width: 25%;">
        <%= this.GetGlobalResourceObject("CourseCompletionReport.aspx", "Reports.CourseCompletionReport.StartDateFrom") %>
    </td>
    <td class="dateverification" style="width: 75%;">
        <asp:TextBox ID="txtStartDateFrom" runat="server" SkinID="TextBoxNoneMandatory" autocomplete="off" contentEditable="false"></asp:TextBox>
        <ajaxToolkit:CalendarExtender ID="defaultCalendarExtender1" Format="MMMM dd, yyyy" runat="server" TargetControlID="txtStartDateFrom" />
        <asp:Label ID="lblStartDateFrom" runat="server" Text="x" class="xlink" ></asp:Label>
    </td>
</tr>

This is one of the parts - textbox + ajax calender + label, if there is something wrong with the structure of the html as well.. So if any of you guys have an idea what should I do to debug this, please respond. 这是其中一个部分 - 文本框+ ajax日历+标签,如果html的结构也有问题。所以,如果你们有任何人知道我应该怎么做来调试这个,请回复。 Thanks in advance. 提前致谢。

I would assume any issues in IE 10 carried over into IE 11. I'm running IE 11 and based on the script and structure you've given, it seems to be working for me. 我认为IE 10中的任何问题都会延续到IE 11.我正在运行IE 11并且基于你给出的脚本和结构,它似乎对我有用。

Here's a fiddle I used. 这是我用过的小提琴。 I tried to replicate what you've shown, replacing a span element with your label since that is what would get rendered and removing the CalendarExtender , which I don't think would matter anyways. 我试图复制你所展示的内容,用你的label替换span元素,因为这将是渲染的内容并删除CalendarExtender ,我认为这无论如何都不重要。

http://jsfiddle.net/Sn7p8/9/ http://jsfiddle.net/Sn7p8/9/

Are you sure that your selector is getting the elements you're expecting? 你确定你的选择器正在获得你期望的元素吗?

As a side note, here is an example of one common practice for storing jquery objects 作为旁注,这里是一个存储jquery对象的常见做法的示例

var Members = 
{
  btnDisplayReport: $('#' + <%= btnDisplayReport.ClientID %>),
  txtStartDateFrom: $('#' + <%= txtStartDateFrom.ClientID %>),
  txtStartDateTo: $('#' + <%= txtStartDateTo.ClientID %>),
  txtCompletionDateFrom: $('#' + <%= txtCompletionDateFrom.ClientID %>)
}

Then, you can use the Members object to access the elements 然后,您可以使用Members对象来访问元素

$(document).ready(function(){
  Members.btnDisplayReport.click(function(){
    ...
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM