Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery不在.html文件中运行_Jquery_Html - Fatal编程技术网

JQuery不在.html文件中运行

JQuery不在.html文件中运行,jquery,html,Jquery,Html,我做错了什么?我试图让我的jquery显示在我的.html文件中,但它没有运行 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> <script> $(".mainNav a").hover(function() { $(thi

我做错了什么?我试图让我的jquery显示在我的.html文件中,但它没有运行

<!DOCTYPE html>
<html>
<head>
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
$(".mainNav a").hover(function() {
    $(this).parent().find(".subNav").slideDown('fast').show();
    $(this).parent().hover(function() {}, function() {
        $(this).parent().find(".subNav").slideUp('fast');
    });
}).hover(function() {
    $(this).addClass("subHover");
}, function() {
    $(this).removeClass("subHover");
});


</script>

$(“.mainNav a”).hover(函数(){
$(this.parent().find(.subNav”).slideDown('fast').show();
$(this.parent().hover(function(){},function()){
$(this.parent().find(“.subNav”).slideUp('fast');
});
}).hover(函数(){
$(此).addClass(“subshover”);
},函数(){
$(此).removeClass(“subshover”);
});
确保:

将所有脚本移动到html的

<body>

<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>

    $(".mainNav a").hover(function() {
        $(this).parent().find(".subNav").slideDown('fast').show();
        $(this).parent().hover(function() {}, function() {
            $(this).parent().find(".subNav").slideUp('fast');
        });
    }).hover(function() {
        $(this).addClass("subHover");
    }, function() {
        $(this).removeClass("subHover");
    });
</script>
</body>
</html>

$(“.mainNav a”).hover(函数(){
$(this.parent().find(.subNav”).slideDown('fast').show();
$(this.parent().hover(function(){},function()){
$(this.parent().find(“.subNav”).slideUp('fast');
});
}).hover(函数(){
$(此).addClass(“subshover”);
},函数(){
$(此).removeClass(“subshover”);
});

2您必须解决的问题

1.在head中添加脚本并使用

<script src="source of jquery"></script>
<script>
$document.ready(function(){

some code jQuery

})
</script>

$document.ready(函数(){
一些jQuery代码
})
2.在标记之前添加脚本


在此处输入代码

这次您不再需要$document.ready()

代码的其余部分在哪里?使用document.ready作为jquery代码。当前jQuery可能稍后加载。HTML部分在哪里?你到底想达到什么目的?将代码包装在
$(document).ready(function(){……..//您的代码……})中我将很快添加代码!控制台中有错误吗?好的,添加它相当难看。添加$(document).ready(函数(){……..//您的代码……});它不起作用了。在codepen.io/SalvatoreSantamaria/pen/gwwajmugger??为什么会这样?你的代码没有参加选美比赛,是吗:)请查看Atlerative解决方案的更新。在你提供的codepen链接下拉列表中,什么对你不起作用?嘿,Lekhnath-codepen工作正常,我只是想让它在.html文件中工作。我仍然无法让它工作,即使在添加文档准备就绪或在标记之前以第二种方式将其移动到正文中
<script src="source of jquery"></script>
<script>
$document.ready(function(){

some code jQuery

})
</script>
<script src="source of jquery"></script> 
<script>

enter code here here

</script>