jQuery导入及测试

jQuery导入:

<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>//将jQuery包引入HTML

<script>jQuery语句</script>//调用jQuery书写jQuery程序

此处src为已经下载的jQuery文件安装目录。

jQuery测试:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
</script>
<script>
if(typeof jQuery == 'undefined'){
    window.alert("没有jquery");
}
</script>
</head>
<body>
<p>如果您点击我,我会消失。</p>
<p>点击我,我会消失。</p>
<p>也要点击我哦。</p>
</body>
</html>

  如果运行后界面上不弹出“没有jquery”的提示以及段落被点击后消失,则导入成功;否则说明没有成功,那么就检测代码吧,一般将jQuery放入项目文件下应该是可以用的,不成功的话多数情况是代码有问题,如某些拼写错误等。

posted @ 2016-11-07 00:47  文歌  阅读(7484)  评论(1编辑  收藏  举报