我正在尝试查找语法以确定div是否具有包含data-role属性设置为header的子div。我没有运气尝试过这些东西:

$('div[data-role*="page"]').each(function(i) {
    if($(this).children('div').attr('data-role')=='header';) {
        alert("has header");
    }
});




$('div[data-role*="page"]').each(function(i) {
    if($(this).children('div[data-role*="header"]').length!=0;) {
        alert("has header");
    }
});

最佳答案

在此示例中,在;之后有一个尾随!=0;

$('div[data-role*="page"]').each(function(i) {
    if ($(this).children('div[data-role="header"]').length != 0) {
        alert("has header");
    }
});


jsfiddle上的示例。

10-02 19:04
查看更多