the focus event seems like asynchronize under IE7/8

here is the test example:

 

under firefox (3.5) :

 

under ie:

 

<textarea cols="50" rows="15" name="code" class="xhtml">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;mce:style type=&quot;text/css&quot;&gt;&lt;!-- div { } --&gt;&lt;/mce:style&gt;&lt;style type=&quot;text/css&quot; mce_bogus=&quot;1&quot;&gt; div { } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Test focus, press any key to switch focus target&lt;/h1&gt; &lt;div id=&quot;d1&quot; style=&quot;display: block;&quot; mce_style=&quot;display: block;&quot; tabindex=&quot;-1&quot;&gt;&lt;/div&gt; &lt;div id=&quot;d2&quot; tabindex=&quot;-1&quot;&gt;&lt;/div&gt; &lt;div id=&quot;d3&quot; tabindex=&quot;-1&quot;&gt;&lt;/div&gt; &lt;mce:script type=&quot;text/javascript&quot;&gt;&lt;!-- function $(id){ return document.getElementById(id); } var idx = 1; document.onkeydown = function() { console.log('focus next', idx); $('d' + idx).focus(); console.log('innerHTML:', $('d' + idx).innerHTML); // output: innerHTML: under ie ++idx; if(idx &gt; 3) idx = 1; } for(var i=1; i != 4; ++i) { $('d' + i).onfocus = function() { console.log(&quot;do focus&quot;); this.innerHTML = this.id; } $('d' + i).onblur = function() { this.innerHTML = ''; } } // --&gt;&lt;/mce:script&gt; &lt;/body&gt; &lt;/html&gt; </textarea>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章