感谢我收到的建议here ,我清理了我的代码,现在使用纯 jQuery。我对发现的脚本做了轻微编辑 here我得到了这个:
window.onload = function(){
var tooltip = $( '<div id="tooltip">' ).appendTo( 'body' )[0];
$( 'img' ).
each(function () {
var pos = $( this ).position(),
top = pos.top,
left = pos.left,
width = $( this ).width(),
height = $( this ).height();
$( this ).
mousemove(function ( e ) {
var x = e.pageX - left,
y = e.pageY - top;
$( tooltip ).text( 'x = ' + x + ', y = ' + y ).css({
left: e.clientX + 10,
top: e.clientY + 10
}).show();
}).
mouseleave(function () {
$( tooltip ).hide();
});
});
};
我有一个问题:我尝试将一行代码更改为:
$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({
但是它不起作用。我没有打破界限,而是得到了这个:
最佳答案
更改:
$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({
至:
$( tooltip ).html( 'x = ' + x + '<br/> y = ' + y ).css({
关于javascript - 图像上的鼠标光标坐标 : <br/> not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11245250/