首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击按钮时.show()无法工作

单击按钮时.show()无法工作
EN

Stack Overflow用户
提问于 2016-08-08 23:26:51
回答 3查看 1.5K关注 0票数 0

我试图隐藏一个div (class=“登录表单”),直到我的jQuery页面上按下登录按钮。但是,当我单击该按钮时,将不会显示登录表单。为什么会这样呢?

谢谢!

代码语言:javascript
复制
<?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>

手写笔( CSS预处理程序,非常类似于CSS)---------------------------------------------------的语法)。

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

发布于 2016-08-08 23:30:51

解决方案:第二个.click()函数(用于#create)缺少函数中的括号。不然就行了。

票数 1
EN

Stack Overflow用户

发布于 2016-08-08 23:33:28

请检查您的代码,您忘记为函数#create-account写"()“。

代码语言:javascript
复制
$('#create-account').click(function(){
    $(".create-account-form").show();
});
票数 0
EN

Stack Overflow用户

发布于 2016-08-08 23:33:34

在您的$("#create-account.click(function ")中添加缺少的括号,它就能工作了。

代码语言:javascript
复制
$(document).ready(function() {
    $("#login").click(function(){
        $('.login-form').show();
    });

    $('#create-account').click(function{ <---- missing "()"
        $(".create-account-form").show();
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38839911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档