<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>error アーカイブ - nyanblog ~にゃんぶろぐ~</title>
	<atom:link href="https://nyanblog2222.com/tag/error/feed/" rel="self" type="application/rss+xml" />
	<link>https://nyanblog2222.com/tag/error/</link>
	<description>ちょっとしたことを調べているよ</description>
	<lastBuildDate>Fri, 15 Nov 2024 06:40:54 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7</generator>

<image>
	<url>https://nyanblog2222.com/wp-content/uploads/2021/09/cropped-favicon-32x32.png</url>
	<title>error アーカイブ - nyanblog ~にゃんぶろぐ~</title>
	<link>https://nyanblog2222.com/tag/error/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>【JS】jQueryでloadが効かない場合の対処法</title>
		<link>https://nyanblog2222.com/programming/5050/</link>
					<comments>https://nyanblog2222.com/programming/5050/#respond</comments>
		
		<dc:creator><![CDATA[nyan2222]]></dc:creator>
		<pubDate>Mon, 02 Jan 2023 14:21:21 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[on]]></category>
		<category><![CDATA[unload]]></category>
		<guid isPermaLink="false">https://nyanblog2222.com/?p=5050</guid>

					<description><![CDATA[<p><img src="https://nyanblog2222.com/wp-content/uploads/2023/01/20230102.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" fetchpriority="high" srcset="https://nyanblog2222.com/wp-content/uploads/2023/01/20230102.png 800w, https://nyanblog2222.com/wp-content/uploads/2023/01/20230102-300x157.png 300w, https://nyanblog2222.com/wp-content/uploads/2023/01/20230102-768x401.png 768w" sizes="(max-width: 800px) 100vw, 800px" />今更な内容にはなりますが…。 jQueryでは2から3にバージョンが上がった際、load関数が廃止されたためon関数を使用して対処するようになりました。 …が、それでも上手くできない…。となったときの備忘録です。まずは、 [&#8230;]</p>
<p>投稿 <a href="https://nyanblog2222.com/programming/5050/">【JS】jQueryでloadが効かない場合の対処法</a> は <a href="https://nyanblog2222.com">nyanblog ~にゃんぶろぐ~</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[<img src="https://nyanblog2222.com/wp-content/uploads/2023/01/20230102.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" srcset="https://nyanblog2222.com/wp-content/uploads/2023/01/20230102.png 800w, https://nyanblog2222.com/wp-content/uploads/2023/01/20230102-300x157.png 300w, https://nyanblog2222.com/wp-content/uploads/2023/01/20230102-768x401.png 768w" sizes="(max-width: 800px) 100vw, 800px" />
<p>今更な内容にはなりますが…。</p>



<p>jQueryでは2から3にバージョンが上がった際、<span class="marker-under">load関数が廃止されたためon関数を使用</span>して対処するようになりました。</p>



<p>…が、それでも上手くできない…。となったときの備忘録です。<br>まずは、load関数からon関数に書き換える方法と、他、注意事項を載せています。</p>




  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">on関数に書き換え</a></li><li><a href="#toc2" tabindex="0">注意事項</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">on関数に書き換え</span></h2>



<p>イベント関連の処理clickイベント同様に、各関数（load、unload、error）での書き方は使用できなくなり、on関数での記述になりました。</p>



<p>■2.Xの書き方</p>



<pre class="wp-block-code javascript"><code>$(window).load(function() {
  // ・・・処理
});

$(window).unload(function() {
  // ・・・処理
});

$(window).error(function() {
  // ・・・処理
});</code></pre>



<p>■3.Xの書き方</p>



<pre class="wp-block-code javascript"><code>$(window).on('load', function() {
  // ・・・処理
});

$(window).on('unload', function() {
  // ・・・処理
});

$(window).on('error', function() {
  // ・・・処理
});</code></pre>



<h2 class="wp-block-heading"><span id="toc2">注意事項</span></h2>



<p>注意事項ですが、<span class="marker-under-red">load処理</span>を行う際に以下のように <strong><span class="marker-under">$(function () {});</span></strong> で囲ってしまうとエラーが起こってしまうので注意してください。&nbsp;</p>



<p><strong><span class="marker-under">$(function () {});</span></strong> は $(document).ready(function() {}); と同じ処理で、ready処理はload処理とは実行するタイミングが異なるため、エラーになってしまいます。</p>



<p>■書き方</p>



<pre class="wp-block-code javascript"><code>$(function () {
  // ・・・処理1
});

$(window).on('load', function() {
  // ・・・処理2
});</code></pre>



<p>■エラー</p>



<pre class="wp-block-code javascript"><code>$(function () {
  // ・・・処理1

  $(window).on('load', function() {
    // ・・・処理2
  });
});</code></pre>



<p>★readとloadの違いの記事を書くかもしれません。</p>



<p></p>



<p></p>



<p></p>
<p>投稿 <a href="https://nyanblog2222.com/programming/5050/">【JS】jQueryでloadが効かない場合の対処法</a> は <a href="https://nyanblog2222.com">nyanblog ~にゃんぶろぐ~</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nyanblog2222.com/programming/5050/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
