<?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>さくらたんどっとびーず &#187; textarea</title>
	<atom:link href="http://sakuratan.biz/archives/tag/textarea/feed" rel="self" type="application/rss+xml" />
	<link>http://sakuratan.biz</link>
	<description>モロモロ工事中です</description>
	<lastBuildDate>Sun, 25 Jun 2023 12:51:51 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>JavaScriptでtextareaのキーボード入力イベントをハンドリングする方法2011年版</title>
		<link>http://sakuratan.biz/archives/3728</link>
		<comments>http://sakuratan.biz/archives/3728#comments</comments>
		<pubDate>Wed, 02 Feb 2011 17:04:23 +0000</pubDate>
		<dc:creator>さくら</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://sakuratan.biz/?p=3728</guid>
		<description><![CDATA[JavaScript プログラマなら、textarea のキーボード入力イベントのハンドリングで一度は苦労したんじゃないかと思います。かく言う私も何度も苦労させられてまっすw で、JavaScript で textarea のキーボード入力イベントを補足する場合、onblur onfocus onchange onkeyup イベントハンドラで行うのが一般的だと思っていたのですが、mozilla（... <div style="margin-top:1ex"><a href="http://sakuratan.biz/archives/3728">(続きを読む)</a></div>]]></description>
			<content:encoded><![CDATA[<p>JavaScript プログラマなら、textarea のキーボード入力イベントのハンドリングで一度は苦労したんじゃないかと思います。かく言う私も何度も苦労させられてまっすw</p>
<p>で、JavaScript で textarea のキーボード入力イベントを補足する場合、onblur onfocus onchange onkeyup イベントハンドラで行うのが一般的だと思っていたのですが、mozilla（firefox 等）の場合 onkeyup の代わりに onpaste oninput をハンドリングするのが良いようです。</p>
<p>ちーと例示がめんどくさいので jQuery 使ってサンプルコードを書きますとこんな感じになります。</p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> events <span style="color: #339933;">=</span> <span style="color: #3366CC;">'blur focus change '</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">mozilla</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'paste input'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'keyup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>events<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// イベントハンドラ</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>これで textarea にキーボード入力が発生したり、マウスで focus/blur したりといった、ユーザーからの I/O はだいたい補足できると思います。</p>
<p>ちなみに <a href="https://developer.mozilla.org/en/DOM/element#Event_Handlers">onpaste は Mozilla のイベント</a>で、<a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">oninput は HTML5 のイベント</a>のようです。</p>
<p>んーっと、上のコード Twitter の JavaScript を参考にしたんですが、onpaste が Firefox3 以降なので Firefox2 以下だと textarea が更新されてから change がイベントされないとトリガできないような気もしますが…<br />
まーえーかww</p>
]]></content:encoded>
			<wfw:commentRss>http://sakuratan.biz/archives/3728/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
