【发布时间】:2017-05-28 03:16:37
【问题描述】:
我添加了一些带有内部 img 标签的 div。每个标签都有自己唯一的 id = "theImg"+i 其中 "i" 是数字。我想将鼠标悬停在特定的 img 上并显示 span 的内容(也有带有数字的特定 id)。到目前为止,这是我的代码,但无法正常工作。
var j;
document.onmouseover = function(r) {
console.log(r.target.id);
j = r.target.id;
}
$(document).on({
mouseover: function(e){
$("span").show();
},
mouseleave: function(e){
$("span").hide();
}
}, "img#"+j);
【问题讨论】:
-
您是说对于每个“theImg”+i 都有一个对应的跨度,其 id 为“theSpan”+i(两者的数字相同)?
-
是的,正确,我在循环迭代中添加了它
标签: javascript jquery mouseevent mouseover onmouseover