私は学習者なので、まだ経験が必要で、多くの質問がありますが、今日はホバー機能について 1 つだけ質問があります。
最初のホバー関数から2番目のホバー関数に変数に関する情報を送信することは可能ですか? これ以上の情報は必要ないと思います。タグの src から一部を変更しているだけです。
あなたが私を理解してくれることを願っています。=)
ここに例があります
http://jsbin.com/eporib/edit#javascript,html,live
今見てはどうですか!
box.hover(function(){
var $this = $(this),
oldImg = $this.find('img').attr('src'),
slicedOldImg = oldImg.slice(0,-5),
newImg = slicedOldImg+num6;
$this.find('img').attr('src', newImg);
$('#hello').append('IN '+newImg);
}, function() {
var $this = $(this),
oldImg = $this.find('img').attr('src'),
slicedOldImg = oldImg.slice(0,-5),
newImg = slicedOldImg+num1;
$this.find('img').attr('src', newImg);
$('#hello').append('OUT '+newImg+ '<br />');
}); /*end Hover*/
そして、どのように私はそれをしたいです
box.hover(function(){
var $this = $(this),
oldImg = $this.find('img').attr('src'),
slicedOldImg = oldImg.slice(0,-5),
newImg = slicedOldImg+num6;
$this.find('img').attr('src', newImg);
$('#hello').append('IN '+newImg);
}, function() {
$this.find('img').attr('src', oldImg);
//look here, the oldImg is in the first function.
// and i want it use it in the second too.
$('#hello').append('OUT '+newImg+ '<br />');
}); /*end Hover*/