$(document).ready(function(){
$('#content1').hide();
$('a#open').click(function(){
$('#content1').show('slow');
});
$('a#close').click(function(){
$('#content1').hide('slow');
})
});
Run Code Online (Sandbox Code Playgroud)
在此代码中,toogle打开和关闭按钮是不同的
<a> 和 <a id="close">
我想要<a>打开和关闭相同的按钮,并希望为打开和关闭位置提供不同的背景图像
$('a').click(function(){
$('#content1').slideToggle();
});
Run Code Online (Sandbox Code Playgroud)
如果您想更改他们的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');
}
});
Run Code Online (Sandbox Code Playgroud)