jQuery切换CSS? [英] jQuery toggle CSS?
本文介绍了jQuery切换CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在CSS之间切换,所以当用户点击按钮(#user_button)它显示菜单(#user_options)和更改CSS,当用户再次点击它回到正常。到目前为止,这是我所有的:
I want to toggle between CSS so when a user clicks the button (#user_button) it shows the menu (#user_options) and changes the CSS, and when the user clicks it again it goes back to normal. So far this is all I have:
$('#user_button').click( function() {
$('#user_options').toggle();
$("#user_button").css({
borderBottomLeftRadius: '0px',
borderBottomRightRadius: '0px'
});
return false;
});
有人可以帮助吗?
推荐答案
$('#user_button').toggle(function () {
$("#user_button").css({borderBottomLeftRadius: "0px"});
}, function () {
$("#user_button").css({borderBottomLeftRadius: "5px"});
});
在这种情况下使用类将比直接设置css更好,看看addClass和removeClass方法alecwh提到。
Using classes in this case would be better than setting the css directly though, look at the addClass and removeClass methods alecwh mentioned.
$('#user_button').toggle(function () {
$("#user_button").addClass("active");
}, function () {
$("#user_button").removeClass("active");
});
这篇关于jQuery切换CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文