为什么这个脚本的DateTimePicker导致IE6和IE7不加载网页 [英] Why does this DateTimePicker script cause IE6 and IE7 not to load page

查看:106
本文介绍了为什么这个脚本的DateTimePicker导致IE6和IE7不加载网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net MVC 3网站,导致IE6和7,提示无法加载页面加载菜单后几页。我已经能够解决此下降到以下的DateTimePicker 脚本:

I have a few pages on a asp.net MVC 3 site that cause IE6 and 7 to prompt "Unable to load page" after loading the menu. I have been able to troubleshoot this down to the following DateTimePicker script:

<script type="text/javascript">
$('#StartDateTime').datetimepicker({
    onClose: function(dateText, inst) {
        var endDateTextBox = $('#EndDateTime');
        if (endDateTextBox.val() != '') {
            var testStartDate = new Date(dateText);
            var testEndDate = new Date(endDateTextBox.val());
            if (testStartDate > testEndDate)
                endDateTextBox.val(dateText);
        }
        else {
            endDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        var start = $(this).datetimepicker('getDate');
        $('#EndDateTime').datetimepicker('option', 'minDate', new Date(start.getTime()));
    }
});
$('#EndDateTime').datetimepicker({
    onClose: function(dateText, inst) {
        var startDateTextBox = $('#StartDateTime');
        if (startDateTextBox.val() != '') {
            var testStartDate = new Date(startDateTextBox.val());
            var testEndDate = new Date(dateText);
            if (testStartDate > testEndDate)
                startDateTextBox.val(dateText);
        }
        else {
            startDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        var end = $(this).datetimepicker('getDate');
        $('#StartDateTime').datetimepicker('option', 'maxDate', new Date(end.getTime()) );
    }
});
</script>

我相信这是它引发错误:

I believe this is the error that it is throwing:

HTML解析错误:无法修改父容器元素
  之后的子元素被关闭

HTML Parsing Error: Unable to modify the parent container element before the child element is closed

现在我已经解决了这个问题,但是我想知道的为什么它摆在首位发生?它是在IE的某些版本的bug?我注意到,在IE7的一个安装如果你安装了标准更新错误消失,有的人说,他们已经对IE8的错误。

Now I have solved this issue, however I want to know why it is happening in the first place? Is it a bug in some versions of IE? I noticed that on one installation of IE7 if you install the standard updates the error goes away, and some people have said that they have had the error on IE8.

基本上,这问题是,我有一个看起来像这样我的MVC布局页:

Basically this issue is that I have my MVC layout page that looks like this:

<!DOCTYPE html>
<html>
<head>
    ...
</head>
<body>
<section>
    @RenderBody()
</section>
<footer>
</footer>
</body>
</html>

和有问题的网页包含这样的:

And the pages that have the issue contain something like this:

<h2>Test</h2>
<form action="/Home/Test" data-ajax="true" data-ajax-loading="#loading-progress"
 data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#results"
 id="form0" method="post">

    Start Time
    <br />
    <input data-val="true" data-val-required="The StartDateTime field is required."
     id="StartDateTime" name="StartDateTime" type="text" value="" />
    <br />

    End Time
    <br />
    <input data-val="true" data-val-required="The EndDateTime field is required."
     id="EndDateTime" name="EndDateTime" type="text" value="" />    <br />
    <br />

    <input type="submit" value="Search" />
    <img id="loading-progress" src="../../Content/images/ajax-loader.gif" alt="loading"/>
</form>

<div id="results"></div>

其次是上面的脚本。因此,与该脚本的页面获取里面呈现的&lt;节方式&gt; 标签

要解决这个问题,所有需要做的是分离格式剧本因此所有我确实是呈现在 @RenderBody()键,如下图所示在 @RenderSection(脚本)剧本

To solve the issue all that needs to be done is to separate the form from the script so all i did was render the form in the @RenderBody() as seen below and the script in the @RenderSection("Scripts").

<!DOCTYPE html>
<html>
<head>
    ...
</head>
<body>
<section>
    @RenderBody()
</section>
<footer>
</footer>
@RenderSection("scripts", false)
</body>
</html>

所以这个固定的问题,但为什么呢?做了&lt;节&GT; 标记需要脚本之前被关闭?更有意思的是,这只是在与的DateTimePicker 脚本的网页有问题。我有一个没有类似的问题,更复杂的脚本许多网页。

So this fixed the question but why? Did the <section> tag need to be closed before the script? More interestingly this is only a problem on pages with the DateTimePicker script. I have many pages with similar and more complex script that has no issues.

推荐答案

完成DOM后,您应该执行该code。封装你code的:

You should execute that code after the DOM is completed. Encapsulate your code in:

$(function () {
    // your code here
});

http://api.jquery.com/ready/

这篇关于为什么这个脚本的DateTimePicker导致IE6和IE7不加载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆