これは誰かにとって非常にシンプルになるだろうが、私はちょうどそれを理解しようと2時間を過ごした。矛盾のないグローバルjQuery変数
jqueryの内部で関数を使用する方法はありません。私はUncaught ReferenceError: swapImages is not defined (anonymous function)
を取得し続けるjqueryを使用しない場合は、コードは正常に動作しません。 (私はそれはワードプレスに組み込まれているとして、競合を使用しないことがあります)
jQuery(document).ready(function ($) {
function swapImages() {
var $active = $('#myGallery .active');
var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');
$active.show(function() {
$active.show().removeClass('active');
$next.show().addClass('active');
});
}
// Run our swapImages() function every 5secs
setInterval('swapImages()', 500);
})
See the original question here
なぜあなたはグローバルスコープであなたの関数を得るいけませんか? –
それで '$ === jQuery'は' window.swapImages = function(){...} 'を使わないと利用できません。しかし、グローバルを使用することはとにかく悪いです... – ThiefMaster