尝试从 .class 的第二个类创建变量。
var post_id = $('.divclass').hasClass('');
$(document).ready(function(){
$(post_id).click(function() {
$(this).fadeIn(1000);
});
});
我知道这是错误的,但也许这里有人可以帮助理解我正在尝试做的事情。 提前致谢。
最佳答案
因此,您需要做的是选择您正在执行的具有多个类的项目:
var post_id = $('.divclass').attr('class');
//Now spilt the string by all of the spaces
post_id.split(" ");
//now refer to the string as an array
//lets get the second one.
post_id[1]
所以对于你的情况
//Added selector in this case a class with '.' this can be changed to be appropriate i.e '#' for an ID
$('.'+post_id[1]).click(function() {
$(this).fadeIn(1000);
});
关于javascript - 从一个类的另一个类创建一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16010281/