Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Php Jquery即使包含在我的html中也没有运行_Php_Jquery_Html - Fatal编程技术网

Php Jquery即使包含在我的html中也没有运行

Php Jquery即使包含在我的html中也没有运行,php,jquery,html,Php,Jquery,Html,因此,我尝试将jquery放在另存为script.js的js文件夹中,然后在html中调用该文件。所以我试着在我的css之前调用它,在我的css之后调用它,甚至在我结束的地方调用它,但是我的jquery没有运行。有人能确定我的问题吗?下面是我如何在index.php中调用script.js的 <!DOCTYPE HTML> <html> <head> <?php include '/php/db.php'; ?> <link rel="sty

因此,我尝试将jquery放在另存为script.js的js文件夹中,然后在html中调用该文件。所以我试着在我的css之前调用它,在我的css之后调用它,甚至在我结束的地方调用它,但是我的jquery没有运行。有人能确定我的问题吗?下面是我如何在index.php中调用script.js的

<!DOCTYPE HTML>
<html>
<head>
<?php include '/php/db.php'; ?>
<link rel="stylesheet" href="style.css">

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

<script type = "text/javascript" src="js/script.js"></script>

<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Paprika" rel="stylesheet">



<title>YFC</title>
</head>

<body>


    <div id = "container" method="post">
        <div class="signup">
            <h1>Sign up</h1>
            <form action="/action_page.php">
              <input class="pop" type="text" name="Sname" placeholder="Fill in your name!"><br><br><br>

              <input class="pop" type="password" name="Slastname" placeholder="Fill in your last name!"><br><br><br>

              <input class="pop" type="text" name="Susername" placeholder="Fill in your username!"><br><br><br>

              <input class="pop" type="password" name="Spassword" placeholder="Fill in your password!"><br><br><br>

              <input class="pop" type="password" name="SRpassword" placeholder="Repeat your password!"><br><br><br>
              <input class="sbutton" type="submit" value="Submit">
            </form>
        </div>

        <div class="signin">
            <h1>Log in</h1>
            <form action="/action_page.php" method="post">
              <input class="pop" type="text" name="Lusername" placeholder="Fill in your username!"> <br><br><br>
              <input class="pop" type="password" name="Lpassword" placeholder="Fill in your username!"> <br><br><br>
              <input class="lbutton" type="submit" value="Log in">

            </form>
        </div>

    </div>

</body>
</html>

当DOM可用时,您需要运行JS代码。现在,您正试图在
.pop
元素存在之前使用它们

要在jQuery中执行此操作,可以使用document.ready事件处理程序:

$(function() {
  $('.pop').mouseenter(function() {
    $(this).css('width', 300);
  }).mouseleave(function() {
     $(this).css('width', 280)                
  });
});
但是,这里有几点需要注意,这可以提高代码的质量。首先,你不应该把CSS规则放在你的JS代码中。而是创建类,然后使用任何jQuery类修改方法(
addClass()
removeClass()
toggleClass()
)根据需要添加/删除它

您还可以使用
hover()
mouseenter
mouseleave
事件下运行代码。如果将其与
toggleClass()
结合使用,则只需提供一个处理程序函数:

$(function() {
  $('.pop').hover(function() {
    $(this).toggleClass('hover');              
  });
});
.pop{宽度:280px;}
.pop.hover{宽度:300px;}
更进一步,您甚至不需要使用JS代码。当鼠标悬停在CSS的
:hover
选择器上时,可以使用该选择器修改元素,如下所示:

.pop{
宽度:280px;
边框:1px实心#C00;
保证金:2倍;
}
.pop:hover{width:300px;}
Pop
流行音乐

当DOM可用时,您需要运行JS代码。现在,您正试图在
.pop
元素存在之前使用它们

要在jQuery中执行此操作,可以使用document.ready事件处理程序:

$(function() {
  $('.pop').mouseenter(function() {
    $(this).css('width', 300);
  }).mouseleave(function() {
     $(this).css('width', 280)                
  });
});
但是,这里有几点需要注意,这可以提高代码的质量。首先,你不应该把CSS规则放在你的JS代码中。而是创建类,然后使用任何jQuery类修改方法(
addClass()
removeClass()
toggleClass()
)根据需要添加/删除它

您还可以使用
hover()
mouseenter
mouseleave
事件下运行代码。如果将其与
toggleClass()
结合使用,则只需提供一个处理程序函数:

$(function() {
  $('.pop').hover(function() {
    $(this).toggleClass('hover');              
  });
});
.pop{宽度:280px;}
.pop.hover{宽度:300px;}
更进一步,您甚至不需要使用JS代码。当鼠标悬停在CSS的
:hover
选择器上时,可以使用该选择器修改元素,如下所示:

.pop{
宽度:280px;
边框:1px实心#C00;
保证金:2倍;
}
.pop:hover{width:300px;}
Pop
流行音乐

Pop
尝试将代码包装在此
$(文档)中。就绪(函数(){})
浏览器控制台中出现了哪些错误?尝试将代码包装在此
$(文档)中。就绪(函数(){})
浏览器控制台中出现了哪些错误?嗯,好的,我看到它现在可以工作了,谢谢:)但是为什么我在body标记末尾调用.js时它不能工作呢?因为DOM应该是可用的,对吗?既然我最后调用了.js文件,那么它应该可以工作了。我只能假设问题是由于你的输入错误-
function
而不是
function
。嗯,好的,我看到它现在可以工作了,谢谢:)但是为什么当我在我的body标签末尾调用.js时它不能工作呢?因为DOM应该是可用的,对吗?既然我最后调用了.js文件,那么它应该可以工作了。我只能假设问题是由于您的输入错误-
功能
,而不是
功能