如何使用jQuery迁移插件?

时间:2021-12-31 00:58:50

I'm using jquery 2.0 but would like to also use the jQuery migrate plugin so my website will work on older browsers. However, I've been unsuccessful at getting it to work. I have the following in the header section in my html.

我正在使用jquery 2.0,但我也想使用jquery migration plugin插件,这样我的网站就可以在旧的浏览器上运行了。然而,我一直没能让它发挥作用。我在html的标题部分有以下内容。

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <script src="/Scripts/jquery-2.0.3.js"></script>
    <script src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="/Scripts/jquery.validate.min.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>

The compatibility meta tag is so I can test this on my computer (which has IE 11). I don't have a computer with an older IE. Anyway, this is giving me javascript errors such as:

兼容性元标签是这样的,我可以在我的电脑上测试它(它有ie11)。我没有一台有旧IE的电脑。总之,这给了我一些javascript错误,比如:

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'addEventListener'

0x800a01b6 - JavaScript运行时错误:对象不支持属性或方法'addEventListener'

The jQuery migrate guide (https://github.com/jquery/jquery-migrate/) seems to just say to include the migrate plugin after including jQuery. What am I doing wrong?

jQuery迁移指南(https://github.com/jquery/jquery-migrate/)似乎只是说在包含jQuery之后包含了迁移插件。我做错了什么?

EDIT

编辑

I found my local jquery.js file must be corrupt or maybe the nuget package I got it from has a bad version of it. Since that error goes away when I include jquery directly from code.jquery.com.

我找到了本地的jquery。js文件一定是损坏的,或者可能是我从nuget包得到的错误版本。因为当我从code.jquery.com直接包含jquery时,这个错误就消失了。

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <script src="http://code.jquery.com/jquery-2.1.0.js"></script>
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>

However, my scripts give an error. Here's an example script

但是,我的脚本会出错。下面是一个示例脚本

function HighlightSelectedRow(tr) {
    $("#TableSummary tr").removeClass("HighlightedRow");
    tr.className += " HighlightedRow";
}

It gives the following error

它给出以下错误

0x800a138f - JavaScript runtime error: The value of the property '$' is null or undefined, not a Function object

Thanks

谢谢

4 个解决方案

#1


6  

May be you should reorder the js stack:

可能你应该重新订购js栈:

<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<script src="/Scripts/jquery-2.0.3.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="/Scripts/jquery.validate.min.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
</head>

#2


3  

Change the order of the include jquery migrate script

更改包括jquery迁移脚本的顺序。

#3


1  

Not likely it was a file corruption, just an incompatibility with jQuery 2.x and IE 8. If you need IE 8 compatibility, use the 1.x series.

不太可能是文件损坏,只是与jQuery 2不兼容。x和IE 8。如果你需要ie8兼容性,使用1。x系列。

This applies even if you are running IE 10 (and I would assume newer). In my case, I had a few PCs with Tools / Compatibility view settings / Display Intranet sites in compatibility view checked. So, it worked fine in Visual Studio on my local PC, but when I "published" to an in house server for the next layer of testing, SPLAT. Some PCs crash and burned, while others were fine.

即使你运行IE 10(我也会假设更新),这也适用。在我的情况下,我有一些带有工具/兼容性视图设置/在兼容性视图检查中显示内部网站点的pc。因此,它在本地PC上的Visual Studio中工作得很好,但是当我“发布”到一个in house服务器进行下一层测试时,SPLAT。有些电脑会崩溃和烧毁,而另一些则安然无恙。

The jQuery download site gives this warning.

jQuery下载站点给出了这个警告。

jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8. ... Since IE 6/7/8 are still relatively common, we recommend using the 1.x version unless you are certain no IE 6/7/8 users are visiting the site.

jQuery 2。x具有与jQuery 1相同的API。但不支持Internet Explorer 6、7或8。由于IE 6/7/8仍然比较常见,我们建议使用1。除非您确定没有IE 6/7/8用户访问该站点,否则将使用x版本。

For those that want to force IE out of compatibility mode,

对于那些想把IE逼出兼容模式的人,

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

can be added at the very top of your master page.

可以在主页的最顶端添加。


Edit

编辑

This code will call the correct version of jQuery for older IEs. It will load 1.x for IE 8 and for 10 in compatibility mode. This can be added in combination with or as a replacement to the Meta value above.

这段代码将为旧的IEs调用正确的jQuery版本。它将会被加载1。适用于ie8,适用于兼容模式下的10。这可以与上述元值合并或作为替换添加。

<!--[if lt IE 9]>
    <script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<!--<![endif]-->

#4


0  

Turning off compatibility mode on IE worked for me.

关闭IE的兼容性模式对我很有效。

#1


6  

May be you should reorder the js stack:

可能你应该重新订购js栈:

<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<script src="/Scripts/jquery-2.0.3.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="/Scripts/jquery.validate.min.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
</head>

#2


3  

Change the order of the include jquery migrate script

更改包括jquery迁移脚本的顺序。

#3


1  

Not likely it was a file corruption, just an incompatibility with jQuery 2.x and IE 8. If you need IE 8 compatibility, use the 1.x series.

不太可能是文件损坏,只是与jQuery 2不兼容。x和IE 8。如果你需要ie8兼容性,使用1。x系列。

This applies even if you are running IE 10 (and I would assume newer). In my case, I had a few PCs with Tools / Compatibility view settings / Display Intranet sites in compatibility view checked. So, it worked fine in Visual Studio on my local PC, but when I "published" to an in house server for the next layer of testing, SPLAT. Some PCs crash and burned, while others were fine.

即使你运行IE 10(我也会假设更新),这也适用。在我的情况下,我有一些带有工具/兼容性视图设置/在兼容性视图检查中显示内部网站点的pc。因此,它在本地PC上的Visual Studio中工作得很好,但是当我“发布”到一个in house服务器进行下一层测试时,SPLAT。有些电脑会崩溃和烧毁,而另一些则安然无恙。

The jQuery download site gives this warning.

jQuery下载站点给出了这个警告。

jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8. ... Since IE 6/7/8 are still relatively common, we recommend using the 1.x version unless you are certain no IE 6/7/8 users are visiting the site.

jQuery 2。x具有与jQuery 1相同的API。但不支持Internet Explorer 6、7或8。由于IE 6/7/8仍然比较常见,我们建议使用1。除非您确定没有IE 6/7/8用户访问该站点,否则将使用x版本。

For those that want to force IE out of compatibility mode,

对于那些想把IE逼出兼容模式的人,

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

can be added at the very top of your master page.

可以在主页的最顶端添加。


Edit

编辑

This code will call the correct version of jQuery for older IEs. It will load 1.x for IE 8 and for 10 in compatibility mode. This can be added in combination with or as a replacement to the Meta value above.

这段代码将为旧的IEs调用正确的jQuery版本。它将会被加载1。适用于ie8,适用于兼容模式下的10。这可以与上述元值合并或作为替换添加。

<!--[if lt IE 9]>
    <script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<!--<![endif]-->

#4


0  

Turning off compatibility mode on IE worked for me.

关闭IE的兼容性模式对我很有效。