0

ここで受け取った提案のおかげで、コードをクリーンアップし、純粋なjQueryを使用しています。ここで見つけたスクリプトを少し編集しました。これがあります。

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();
            }); 

    });

};

問題があります:コードの1行を次のように変更しようとしました:

$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({

しかし、それは機能しません。行を壊す代わりに、私はこれを取得します:

改行が機能しない

4

1 に答える 1

2

変化する:

$( tooltip ).text( 'x = ' + x + '<br/> y = ' + y ).css({

に:

$( tooltip ).html( 'x = ' + x + '<br/> y = ' + y ).css({
于 2012-06-28T13:06:59.670 に答える