var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class');
if (currentClassName == undefined) {
currentClassName = $(this).parent('td').find('input:text').attr('class');
}
这有效,但我想它可以写成一行?我对这个解决方案并不满意。感谢
答案 0 :(得分:1)
if ($(#elm).is('.classname')) { //#elm has the class } else { //#elm doesn't have the class }
答案 1 :(得分:0)
var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class');
currentClassName = (currentClassName == undefined ? $(this).parent('td').find('input:text').attr('class') : currentClassName);
答案 2 :(得分:0)
实际上,我认为您应该能够使用属性jQuery选择器来检查类的存在:
if ($(this).parent('td').next('td').find('input:text[class]').length != 0) {
// do something
}