gpt4 book ai didi

jquery - 如何使用 jquery 添加/删除类或样式

转载 作者:行者123 更新时间:2023-11-28 09:05:10 25 4
gpt4 key购买 nike

我有以下代码,它显示嵌套的 ul 并在单击时隐藏其他打开的。我的问题是如何向打开嵌套 ul 的父 li a 添加背景图像并从它关闭的父 li a 中删除背景图像?

这是我的 jquery:

$(document).ready(function() {
$('ul ul').hide();

$('ul li > a').click(function(event) {
$('ul ul').hide('slow');
$(this).parent().find('ul').show('slow');
});

});;

最佳答案

// will add the class
$('#item').addClass('myClass');

// will remove the class
$('#item').removeClass('myClass');

// will toggle the class (add it if doesn't have it or remove it if it does)
$('#item').toggleClass('myClass');

和内联样式;

// will override those properties
$('#item').css({'color':'red','background':'blue'});

关于jquery - 如何使用 jquery 添加/删除类或样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8913086/

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