【问题标题】:Jquery is not working on websiteJquery 无法在网站上运行
【发布时间】:2016-05-19 18:48:24
【问题描述】:

我已经在 heroku 上部署了我的 nodejs 应用程序。应用部署成功。当我加载网站时,它加载得很好。我检查了网络调用,并且网站中正在加载 Jquery,但是 jQuery 在我的网站上不起作用。一旦 jquery 准备好,就不会出现应该出现的警报框。加载 jquery 时不会出现应该出现的日志。我不知道为什么会这样。以下是代码:

  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
    <script type = "text/javascript"
            src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

  </head>
  <body>
  <h1><%= title %></h1>
  <p>Welcome to <%= title %></p>


  <script type = "text/javascript" language = "javascript">


$(document).on("pageload",function(){
    alert("pageload event fired!");
});

$(document).on("ready",function(){
    alert("page ready event fired!");
    console.log("page ready");
});
    jQuery(document).ready(function() {console.log("ready");});
</script>
</head>

应用运行良好,jquery 在本地主机上运行良好。

【问题讨论】:

  • 也许你只需要更正一些细节,比如最后一个标签,应该是“脚本”,而不是“头”。
  • 其他改进,不要使用“language='javascript'”。只需 "type='text/javascript'" 就可以了。
  • 这只是我在这里发布的代码的错字。
  • 好的,为了确定,你把所有这些都放在 之间,对吧?

标签: javascript jquery node.js heroku mean-stack


【解决方案1】:

您的代码一团糟。头部有一个额外的结束标签,脚本没有结束标签。更改最后的&lt;/head&gt; to &lt;/script&gt;

【讨论】:

    【解决方案2】:

    试试这个:

    <head>
        <title>
            <%= title %>
        </title>
        <link rel='stylesheet' href='/stylesheets/style.css' />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    
    </head>
    
    <body>
        <h1><%= title %></h1>
        <p>Welcome to
            <%= title %>
        </p>
    
    
        <script type="text/javascript">
            $(document).on("pageload", function() {
                alert("pageload event fired!");
            });
    
            $(document).on("ready", function() {
                alert("page ready event fired!");
                console.log("page ready");
            });
            jQuery(document).ready(function() {
                console.log("ready");
            });
        </script>
    </body>
    

    &lt;/head&gt; 更新为&lt;/script&gt;

    删除的语言 = "javascript"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 2015-08-07
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多