2011-03-22 13 views
1

divのHTMLをリンクonMouseoverのタイトルで完成させるスクリプトを作成しました。それは動作していません。JQueryタイトルこの関数の属性

CODE

function title(id) { 
    var thetitle = $(id).attr('title'); 
    $('#top_video_title').fadeTo(100, 0.001); 
    $('#top_video_title').html(thetitle, function(){ 
     $('#top_video_title').fadeTo(200, 1); 
    }); 
    return false; 


} 

HTML

<a href="#" onmouseover="title(this);" onmouseout="titleout()" title="testing">test</a> 
<a href="#" onmouseover="title(this);" onmouseout="titleout()" title="testing2">test2</a> 

任意のアイデア?

マーベラス

答えて

0
this 

$(this) 

に等しくないこともthis interesting articleを参照してください。その後、

function title(id) { 
    var thetitle = id.attr('title'); 
    $('#top_video_title').fadeTo(100, 0.001); 
    $('#top_video_title').html(thetitle, function(){ 
     $('#top_video_title').fadeTo(200, 1); 
    }); 
    return false; 
} 

とあなたのhtmlで$(this)を使用します:

<a href="#" onmouseover="title($(this));" onmouseout="titleout()" title="testing">test</a> 
<a href="#" onmouseover="title($(this));" onmouseout="titleout()" title="testing2">test2</a> 
0

私が代わりにこれを行うことをお勧めしたい:

は、私はあなたがより良いあなたの関数のパラメータとして、あなたのjQueryオブジェクトを送信すると思います

$(document).ready(function() { 
    /* all links with a title -- alternatively, target with classes or ids */ 
    $("a[title]").hover(function(e) { /* function formerly known as "title" */ 

     /* "this" variable in event listener is automatically 
     the element the event was called on*/ 
     var thetitle = $(this).attr('title'); 

     /* duration == 100 ms 
      opacity == 0.001 
      callback -> called after finished fading out 
     */ 
     $('#top_video_title').fadeTo(100, 0.001, function(){ 
      $('#top_video_title').html(thetitle); 
      $('#top_video_title').fadeTo(200, 1); 
     }); 
     return false; 
    } 
    , function(e) {/* function formerly known as "titleout", suitably modified*/ 
    }); 
}) 

これはHTMLの場合:

<!-- no more inline JS :-) --> 
<a href="#" title="testing">test</a> 
<a href="#" title="testing2">test2</a> 
0

JQueryはtitle()という関数の使用を容易にしてくれないようです。私はAPIのコンパイルで使用されているが、関数名が変更されるとすぐに関数全体が完全に機能するため、これがわかりません。

私たちが関数名を変更する前に、それに関するfirebugレポートがありました - 機能を見つけることができませんでした。

function titlein(id) { 
    var thetitle = $(id).attr('title'); 
    $('#top_video_title').fadeTo(50, 0.001, function() { 
    $('#top_video_title').html(thetitle); 
     $('#top_video_title').fadeTo(200, 1);}); 
    return false; 
} 

マーベラス

関連する問題