1

我有一个大型的 asp.net 2.0 应用程序。在当前页面中,我有一个

<head id="head1" runat="server">带有一些元信息,并且原始开发人员已在<body>标签中编写了所有 Javascript 函数。现在我想实施

$(document).ready(function load()
    // My code 
});

当我在我的 head/body 标签中包含 jquery-1.8.3.js 时,其他 javascript 函数无法正常工作。我能做些什么来解决这个问题?

 <head id="Head1" runat="server">`
 <script language="javascript" type="text/javascript" src="JScript/jquery-1.8.3.js"/>`
 <meta http-equiv="Expires" content="0" />
 <meta http-equiv="Cache-Control" content="no-cache" />
 <meta http-equiv="Pragma" content="no-cache" />
 <title>HMS</title>
 <link href="Css/MyStyleSheet.css" rel="stylesheet" type="text/css" />
 </head>

身体

<body>
<script language="javascript" type="text/javascript" src="JScript/MediReckonerJscript.js">
</script>
//some javascript functions here that are not firing since i added jquery reference in the head section. if that is removed this function works well.

我在正文中使用 jQuery 库的脚本。

<script type="text/javascript" language="javascript"> 
//This is my script in the <body> tag.
jQuery.noConflict();
$(document).ready(function load() {
  var iFrame = $('#PageFrame');

iFrame.bind('load', function() { //binds the event
    alert('iFrame Reloaded');
});
});
</script>
4

2 回答 2

1

也许这可能是版本问题,请检查同一库的一些较低版本,也可以使用 jQuery.noConflict(); 对于 jQuery 是冲突的或 $.noConflict(); 如果 $ 是冲突的。

像这样使用 noConflict()

 <script type="text/javascript" language="javascript"> 
//This is my script in the <body> tag.
var j = jQuery.noConflict();
j(document).ready(function load() {
  var iFrame = j('#PageFrame');

iFrame.bind('load', function() { //binds the event
    alert('iFrame Reloaded');
});
});
</script>
于 2013-03-07T09:49:15.240 回答
0

如果您的页面中有其他库,请添加此内容。

jQuery.noConflict();

像原型这样的库使用与 jQuery 相同的“$”,因此它们会发生冲突。

于 2013-03-07T09:35:34.020 回答