我可以通过使用此代码找到元素的文本.但是我想在我的页面中找到一个单词,如果鼠标在该单词上停留一段时间.
$(document).bind("mouseover", function (e) {
var event = e;
setTimeout(function () { $(event.target).contents().each(function(index, elem) {
if( elem.nodeType === 3 && $.trim(elem.nodeValue).length ) {
var text = $.trim(elem.nodeValue);
text = text.split(" ");
console.log($.trim(elem.nodeValue));
//alert($.trim(elem.nodeValue));
return false;
}
});
}, 5000);
Run Code Online (Sandbox Code Playgroud)
});
这可能不是有史以来最好的代码,但它可能会让你走上正确的轨道,取决于andyb的评论.
就像是
$(".first").on("hover",function(){
var words = $(this).text().split(" ");
var fullText = "";
for(i=0;i<words.length;i++){
words[i] = "<span>"+words[i]+"</span> ";
fullText += words[i];
}
$(this).text("").append(fullText);
$(this).children("span").on("hover", function(){
$(".second").text($(this).text());
});
});
Run Code Online (Sandbox Code Playgroud)
虽然查看工作示例是您最好的选择.
| 归档时间: |
|
| 查看次数: |
1526 次 |
| 最近记录: |