gpt4 book ai didi

jquery - 如何在这个 jquery 代码中制作一个用于打开和关闭 div 的按钮?

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:53 25 4
gpt4 key购买 nike

 $(document).ready(function(){

$('#content1').hide();

$('a#open').click(function(){

$('#content1').show('slow');

});

$('a#close').click(function(){
$('#content1').hide('slow');
})

});

在这个toogle打开和关闭按钮的代码中是不同的

<a><a id="close">

我想制作相同的按钮 <a>用于打开和关闭,并希望为打开和关闭位置提供不同的背景图像

最佳答案

$('a').click(function(){
$('#content1').slideToggle();
});

如果你想改变他们的css,你可以用下面的方式重写。

$('a').click(function(){

if ($('#content1').is(":visible"))
{
//change your css here
//for eg. $(#content1).css('background-image', first_image);
$('#content1').hide('slow');
}
else{
//change your css here
//for eg. $(#content1).css('background-image', second_image);
$('#content1').show('slow');
}

});

关于jquery - 如何在这个 jquery 代码中制作一个用于打开和关闭 div 的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3044004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com