這是真實的情況: 正如我說我有12級不同的DIV的和喜歡this.I頁面已鏈接的js文件已經 的index.html:jQuery的ATTR方法不能在正常工作「OnMouseEnter在」
<div id="images_puzzle">
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
<div>
<img />
<p></p>
</div>
</div>
</div>
注意到我已將Jquery.js與我自己的js文件結合在一起。 這是我無法得到我想要的東西的地方。通過將鼠標懸停在每個圖像上我想調用一個函數,所有其他屬性都運行良好,但這不是。
webroot.js:
function setPuzzleImages() {
// alert('loading images...');
var $index = 1;
var $IMGs = $('#images_puzzle IMG');
$IMGs.each(function() {
$(this).attr({ 'src': 'images/105-100/' + $index + '.jpg','onmouseover':'showTitle('+$index+');'});
$index++;
});
}
function showTitle($index) {
alert('this is the'+$index+'image');
}
多一點解釋,請 –
@AliRashidi谷歌'.prop()'它不需要更多的解釋 –
http://jsfiddle.net/vQ366 /完美的作品 –