我希望能够将鼠标悬停在 <div>
上并使用 JavaScript 获取信息(例如 id
)并将其存储在变量中。
实现这一目标的最有效方法是什么?
最佳答案
这将为您做这件事:
$('div').mouseover(function(){
var content = $(this).html();
var id = $(this).attr('id');
alert('the element\'s ID is: '+id+'and content is: '+content);
});
关于javascript - 当鼠标悬停在 div 上时获取该 div 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6823448/