使用Jquery在按钮单击上隐藏/显示Div [英] Hide/Show Div on button click using Jquery

查看:56
本文介绍了使用Jquery在按钮单击上隐藏/显示Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是我正在编写的第一个Jquery代码.我已经使用 this 和更多示例来制作最简单的jquery代码来显示你好,点击按钮(W3Schools值得一提).我试图在单击按钮时显示一个其中包含Hello的div.

This is supposed to be my first Jquery code that I am writing. I have used this and many more examples to make the simplest jquery code to display Hello on Button Click(W3Schools worth mentioning). I am trying to show a div that contains the Hello in it on a button click.

<div>
<input type="button" id="btn" class="btn btn-default" value="click me">
</div>

<div id="Create" style="visibility:hidden">
Hello
</div>

@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(document).ready(function () {
    $(btn).click(function () {
        $(Create).show();

    });
});
</script>
}

我曾尝试在许多地方编写Script代码,例如在Scripts.Render之后,在其顶部.我不确定我应该在哪里放置Jquery代码.

I have tried writing the Script code many places like in the head, after the Scripts.Render, before it. I am not really sure where i should place the Jquery code.

我将此代码附加到了MVC5应用程序中.编写此代码是出于学习目的.我认为View中的其他代码与Jquery的工作无关.

I have this code appended to a MVC5 application. This code is written for learning purpose. I think the other code in the View is irrelevant for the working of the Jquery.

推荐答案

<div>
<input type="button" id="btn" class="btn btn-default" value="click me">
</div>

<div id="Create" style="display:none">
Hello
</div>

@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(document).ready(function () {
    $("#btn").click(function () {
        $("#Create").toggle();
    });
});
</script>
}

这篇关于使用Jquery在按钮单击上隐藏/显示Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆