即使使用了cdn,Jquery也无法正常工作?

时间:2018-02-17 16:26:25

标签: jquery

我写了正确的jquery代码,但它没有用。请帮忙! 请访问该链接 对于HTML文档:https://drive.google.com/file/d/1RckO-f3czHvvWTbLiKcKw9LfV3YgJK6W/view?usp=sharing  对于jquery代码:https://drive.google.com/file/d/1Rhthb2ryzH7y4Cqv-3fCOORnVA5QaGLw/view?usp=sharing  对于css代码:https://drive.google.com/file/d/1kvP_L48-ajNRcHxRp9VEx-voqv3vQa1e/view?usp=sharing 我甚至使用cdn进行jquery并保存了jquery文件,但它没有用。请帮忙!

2 个答案:

答案 0 :(得分:0)

首先尝试在依赖于jquery的自定义代码之前加载jquery库。

例如:

 <script src="http://code.jquery.com/jquery-3.3.1.min.js"
 integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
 crossorigin="anonymous"></script>
 <script src="loginscript.js"></script>

此外,您提供的代码存在错误...(例如)

<img src="logo.jpg id="logo"> // missing quotes

最后,你在开始的body标签之后写了脚本...尝试将它移到关闭body标签之前的底部或者将它们全部包含在你的loginscript中(请参阅下面的更改作为示例,注意jquery上的更改使用)。

$(document).ready(function(){
$("#signupbtn").click(function(){
$("#signupdiv").slideDown(1000);
$("#logindiv").hide();
});


$("#virtualkeyboard").hide();
$("#signupdiv").hide();


$("#virtualkey").click(function(){
$("#virtualkeyboard").slideDown(1000);
$("#prediv").height(300);
});
$("#closebtn1").click(function(){
$("#virtualkeyboard").hide();
$("#prediv").height(600);
});
}

);


function checkcookie(){
var username=getCookie("username");
if (username != ""){
    alert('Welcome again'+username);
    window.location="accounts.html";
}
else{
    window.location="login.html";
}
}

$("#signupbtn").click(function(){
    $("#signupdiv").slideDown(1000);
    $("#logindiv").hide();
});
$(function() {
    $("#virtualkeyboard").hide();
    $("#signupdiv").hide();
    $("username").hide();
});
$("#virtualkey").click(function(){
    $("#virtualkeyboard").slideDown(1000);
    $("#prediv").height(300);
  });
    $("#closebtn1").click(function(){
    $("#virtualkeyboard").hide();
    $("#prediv").height(600);
});


function logincheck(){
var user = document.getElementById('username');
var pass=document.getElementById('password');
if (user.value ==ayush && pass.value==anand){
    document.cookie="username=ayush; expires= mon 19 feb 2018; path=/";
}
else{
    window.location="login.html";
    incorrectusername();
}
}

为你的html,像这样(注意html标签安排的修复)

    <!doctype HTML>
    <head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1.0, maximum-scale=1" />
    <link rel="stylesheet" href="loginstyle.css">
    <!--
    #0095d9;
    #d3d3d3 #0a242b #3f3f3f
    -->

    <title>Ayush Web: Login</title>
    </head>
    <body>

    <div id="welcomediv">
    <div id="prediv">
    <img src="welcomeimg.jpg" id ="welcomeimg">
    </div>
    <div id="virtualkeyboard">
    virtual keyboard here
    </div>
    <div id ="forgotpassword">
    forgot password form here
    </div>
    </div>
    <div id="maindiv">
    <div id="logindiv">
    <br><br><br><br><br>
    <img src="logo.jpg" id="logo">
    <br><br>
    <h id="lohintitle"> Login </h>
    <br><br>
    <input type="text" id="username" placeholder="your username">
    <br><br>
    <input type="password" id="password" placeholder="your password">
    <br><br>
    <a href="#"> Forgot password?</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <button id="loginbtn" onclick="logincheck()">Sign In</button>
    <hr class="hr">
    <button id="virtualkey">Use Virtual Keyboard</button>
    &nbsp;&nbsp;
    <button id="signupbtn">Join Now</button>
    </div>
    <div id="signupdiv">
    <br><br><br><br><br>
    <img src="logo.jpg" id="logo">
    <br><br>
    <h id="logintitle"> Sign Up</h>
    <br><br>
    <input type="text" name="fname" placeholder=" your first name" required>
    &nbsp;&nbsp;
    <input type="text" name="lname" placeholder=" your last name">
    <br><br>
    <input type="email" name="email" placeholder=" your email">
    <br><br>
    <input type="password"  id ="newpassword" name="password" placeholder=" your password" required>
    <br><br>
    <input type="password"  id ="confirmpassword" name="password" placeholder=" confirm your password" required>
    <br><br>
    <button onclick="signupfrmdata()" id="signupfrmbtn">Finish</button>
    <hr class="hr">
    <label>Have an account?</label>&nbsp;&nbsp;
    <button id="loginbtn"> Sign In</button>

    </div>
    </div>



    <script
    src="http://code.jquery.com/jquery-3.3.1.min.js"
    integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
    crossorigin="anonymous"></script>

    <script src="loginscript.js"></script>
    </body>
    </html>   

答案 1 :(得分:0)

在您的html文件中,在此“<title> Ayush Web: Login </ title>”代码之后和<div id = "welcomediv">之前开始

 <title> Ayush Web: Login </ title> </head> <body> <div id = "welcomediv"> ....</body>

你的头不在一个好地方。在这些更正之后在头标记上添加以下行

<script
  src = "http://code.jquery.com/jquery-3.3.1.min.js"
  integrity = "sha256-FgpCb / KJQlLNfOu91ta32o / NMZxltwRo8QtmkMRdAu8 ="
  crossorigin = "anonymous"> </ script>