【问题标题】:When i include jquery.js in markup other javascript functions in the page are not firing当我在标记中包含 jquery.js 时,页面中的其他 javascript 函数不会触发
【发布时间】:2013-02-22 08:50:38
【问题描述】:

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

【问题讨论】:

  • 首先,您必须提供更多信息。你得到什么错误?我看到你在load() 之后忘记了{,但也许这只是一个错字。
  • 您的页面中包含多少个 jquery 库?
  • 而且您的页面是否包含 UpdatePanel 或 ajax 调用
  • 我需要更多上下文来理解问题,哪些功能不起作用?那些原始代码使用不同的jQery版本,那些原始代码定义了自己的$-function ....
  • @codebrain 请参考之前的链接stackoverflow.com/questions/301473/…

标签: javascript jquery asp.net html


【解决方案1】:

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

jQuery.noConflict();

prototype 之类的库使用与 jQuery 相同的“$”,因此它们会发生冲突。

【讨论】:

    【解决方案2】:

    也许这可能是版本问题,请检查同一库的一些较低版本,也可以使用 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>
    

    【讨论】:

    • 我认为这听起来很聪明。会检查的。
    • 但这并没有阻止我的子菜单加载脚本。相反,如果我添加 jQuery.noConflict();在 head 部分的末尾,一切似乎都运行良好! ?
    猜你喜欢
    • 2020-01-23
    • 2014-07-29
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多