2016-05-19 106 views
0

我已经在heroku上部署了我的nodejs应用程序。该应用程序已成功部署。当我加载网站时,它加载正常。我检查了网络调用,并且Jquery被加载到网站中,但是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在本地主机上运行良好。

+0

也许你只需要纠正一些细节,比如最后一个标签,应是“脚本”,而不是“头”。 – Uilian

+0

其他改进,请勿使用“language ='javascript'”。只是“type ='text/javascript'”很好。 – Uilian

+0

这只是我在这里发布的代码的一个错字。 – user2498079

回答

0

你的代码乱七八糟。头部的额外结束标记,脚本没有结束标记。改变最后的</head> to </script>

0

试试这个:

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

更新</head></script>

删除语言= “JavaScript的”

相关问题