鼠标光标坐标在图像上:不工作

感谢我在这里收到的建议,我清理了我的代码,现在我正在使用纯jQuery。 我对我在这里找到的脚本做了一些编辑,我得到了这个:

window.onload = function(){ var 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 + '
y = ' + y ).css({

但它不起作用。 而不是破坏线,我得到这个:

换行不行

更改:

 $( tooltip ).text( 'x = ' + x + '
y = ' + y ).css({

至:

 $( tooltip ).html( 'x = ' + x + '
y = ' + y ).css({