我有以下功能:
$(document).ready(function () {
$('.contents').hide();
$('.slide').click(function () {
var $this = $(this);
$(this).siblings('.contents').slideToggle(200, function () {
$this.text($(this).is(':visible') ? 'close' : 'open');
});
});
});
并且想为点击功能添加更多功能。我是 jQuery 的新手,尝试学习但仍然不明白如何阅读它。我以为我可以创建并附加一个 if 子句,但仍然为此苦苦挣扎。 所以我有类似的东西:
$this.css($('.year').is(':visible') ? 'color', 'red' : 'color', 'green');
if the click function takes place and the .contents is visible change the css setting of .year to red and if not use color green
如果有人能帮助我,那就太好了。
非常感谢。
最佳答案
这是你要找的吗?
$(document).ready(function () {
$('.content').hide();
$('.slide').click(function () {
var $this = $(this);
$(this).siblings('.content').slideToggle(200, function () {
$this.text($(this).is(':visible') ? 'click to close' : 'click to open');
$(this).closest('.aai').find('.head').css('color', $(this).is(':visible') ? 'red' : 'green');
});
});
});
关于javascript - 改变 CSS 的 jQuery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16761214/