我想从 $el.html 中选择特定的子元素,有两种类型的子元素,一种带有<span>....</span>
,另一种有 span 类<span class = "special">..</span>
,例如:
var orig = $(".example").html()
,$el = $(".example")
,text = $.trim($el.text())
,words = text.split(" ")
,html = "";
for (var i = 0; i < words.length; i++) {
if (words[i] === "senior")
html += "<span class='special'>" + words[i] + ((i+1) === words.length ? "" : " ") + "</span>";
else
html += "<span>" + words[i] + ((i+1) === words.length ? "" : " ") + "</span>";
};
$el.html(html).children().hide().each(function(i){
// if $('span.special')
$(this).delay(i*200).fadeIn(700);
// else (normal span)
$(this).delay(i*600).fadeIn(900);
}).promise().done(function(){
$('.example:first').html(orig)
})
在我的“每个”调用中,如何区分有和没有类的跨度?
工作演示在这里:http: //jsfiddle.net/6czap/15/