html如何做个链接,一点击就在下面显示隐藏的文字内容

html如何做个链接,一点击就在下面显示隐藏的文字内容,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签中,输入js代码:

$('button').click(function () {$('div').css('display', 'block')})

3、浏览器运行index.html页面,会有个显示按钮

4、点击显示按钮,此时被隐藏的内容显示了出来。

给按钮上绑定一个onclick事件,同时置一个状态值,状态值为true时显示按钮。

具体代码如下:

<html>

<head>

<script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_f2fb5194.js"></script>

</head>

<body>

<button id="a">btn1</button>

<button id="b">btn2</button>

<script>

$(document).ready(function()

{

$("#a").click(function()

{

$("#a").hide()

})

$("#b").click(function()

{

$("#a").show()

}

)

})

</script>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6156271.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-16
下一篇 2023-03-16

发表评论

登录后才能评论

评论列表(0条)

保存