当我在标记中包含jquery.js时,页面中的其他javascript函数不会触发

时间:2013-03-07 08:30:33

标签: javascript jquery asp.net html

我有一个大型的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 Library。

<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>

2 个答案:

答案 0 :(得分:1)

也许这可能是版本问题,请检查相同库的某些较低版本,也可以使用jQuery.noConflict();因为jQuery是冲突的OR $ .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>

答案 1 :(得分:0)

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

jQuery.noConflict();

像prototype这样的库使用jQuery使用的相同'$',因此它们发生冲突。