简体   繁体   English

.show()在单击按钮时不起作用

[英].show() not working when button is clicked

I am trying to hide a div (class="login-form") until the Login button is pressed on my HTML page using jQuery. 我试图隐藏一个div(class =“ login-form”),直到使用jQuery在我的HTML页面上按下“登录”按钮为止。 However, when I click the button, the login form isnt displayed. 但是,当我单击按钮时,不会显示登录表单。 Why is this? 为什么是这样?

Thanks! 谢谢!

HTML--------------------------------------------------------------------------- HTML ------------------------------------------------- --------------------------

<?php /* Template Name: Virtual-tour */ ?>
<head>

<link rel="stylesheet" href="stylus/main.css"/>
<link href='https://fonts.googleapis.com/css?family=Alegreya+Sans' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- <script src=js/showLogin.js></script>
<script src=js/showCreateAccount.js></script>
<script src=js/submitLogin.js></script>
<script src=js/submitCreateAccount.js></script>
<script src=js/validate.js></script> -->

</head>

<body>

<div class="virtual-tour-media-player">

    <span> placeholder for media player</span>

</div>

<div class="instructions">

    Are you a family member or friend of a veteran on this memorial?</br></br>
    <span id="instruction-sub">
        Login or Create Account below to add additional information and memories.</br>
    </span>

    <button id="login">Login</button>
    <button id="create-account">Create Account</button>

</div>

<div class="login-form">
    <form>
        <input type="text" placeholder="Email Address" />
        <input type="password" placeholder="Password" />
    </form>
</div>

<script>
    $(document).ready(function() {
        $("#login").click(function(){
            $('.login-form').show();
        });

        $('#create-account').click(function{
            $(".create-account-form").show();
        });
    });
</script>

Stylus (a CSS preprocessor, very similar syntax to CSS)--------------------------------------------------- 手写笔(一种CSS预处理器,与CSS非常相似的语法)-------------------------------------- -------------

body
    color #ffffff
    background-color #292929
    font-family 'Alegreya Sans', sans-serif

.virtual-tour-media-player
    width 90%
    height 40%
    margin auto
    border 3px solid white

.instructions
    padding-top 30px
    margin auto
    margin-top 5%
    font-size 100%
    width 45%
    height 22%
    text-align center
    background-color #740600
    box-shadow 2px 2px 2px 2px #232421

#instruction-sub
    font-size 15px
    //color #4d4d4d

button
    line-height 1.8
    border none
    color #f1f1f1
    background-color #0c083e
    margin auto
    margin-top 10%
    width 40%
    height 15%


button:hover
    background-color #292929

.login-form
    display none

SOLUTION: The second .click() function (for #create-account) was missing the parentheses in the function. 解决方案:第二个.click()函数(用于#create-account)缺少该函数中的括号。 It works otherwise. 否则它将起作用。

Check your code please, you forget write "()" for function #create-account 请检查您的代码,您忘记为功能#create-account写入“()”

$('#create-account').click(function(){
    $(".create-account-form").show();
});

Add the missing parenthesis in your $("#create-account.click(function ") and it will work. $("#create-account.click(function ")添加缺少的括号,它将起作用。

$(document).ready(function() {
    $("#login").click(function(){
        $('.login-form').show();
    });

    $('#create-account').click(function{ <---- missing "()"
        $(".create-account-form").show();
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM