ホームページ  >  記事  >  ウェブフロントエンド  >  これら 2 つの方法の違いは何ですか? _html/css_WEB-ITnose

これら 2 つの方法の違いは何ですか? _html/css_WEB-ITnose

WBOY
WBOYオリジナル
2016-06-24 11:41:27886ブラウズ

1、Jquery Moblie の初期化イベントの不実行
$(document).on('pageinit',function() {
var mySwiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination' 、
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
spaceBetween: 30,
centeredSlides: true、
autoplay: 2500、
autoplayDisableOnInteraction: false
});

要使用$(function(){
var mySwiper = new Swiper('.swiper-container',{
pagination : '.swiper-pagination',
grabCursor: true,
paginationClickable: true 、
mousewheelControl :true,// 鼠标滚轮
autoplayDisableOnInteraction:false,
autoplay:10000,
speed: 800,
mode: 'horizo​​ntal',/*纵向滚動*/
})
});

JqueryMobile の「$」 (document).on('pageinit',function() {” 和 “$(function(){”何か么違いますか???

JqueryMobile の“$(document).on('pageinit',function() { ” は最初の追加実行です。

$(function(){何番目の時間実行ですか???回复讨论(解决方案)

$(function(){...}
在页面追加完了(つまり window.load イベント発生)時に実行
所以すべての jq の预处理代网都应放在他里面
如果放在外面,则jq のアップロードが完了せずに

スワイパーが使用されていないことが原因で、2 つのイベントが前のページにあるため、pageinit イベントが発生したときにスワイパー内の一部の画像が追加されていない可能性があります。 $(function(){}) は jquery ready() メソッドの記述であり、完全に $(document).ready(function(){});、当然 $(document).on です。 ('ready',function(){}); このように記述することもできます。
ready は、DOM(テキストオブジェクトモデル)がダウンロードされ、トップページ(画像を含む)が完全に表示された時点で、ready イベントが発生します。

以下を参照



<!doctype html><html><head><meta charset="utf-8"><title></title><link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"><script src="http://code.jquery.com/jquery-1.8.3.min.js"></script><script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script><script>$(document).on('ready',function(){	alert("ready");//这时图片已经显示了});$(document).on('pageinit',function(){	alert("pageinit");//不要点确定,很明显图片还没显示});</script></head><body><img src="http://static.csdn.net/public/common/toolbar/images/f_icon.png" /></body></html>

上で、各位大神を転送します。


は、選択要素上で 1 つまたは複数のイベントのイベント処理関数を決定します。のjQueryオブジェクトjQuery 1.7 では、.on() メソッドは、イベント処理プログラムを決定するために必要なすべての機能を提供します。古い jQuery イベント メソッドからの移行を支援します。.bind()、.delegate()、および .live( を参照) )。 イベントを追加する必要があり、一度だけ実行し、その後自己を削除し、 阅.one() を参照してください

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。