jQueryã®IE6ã®ãã°ãå ±åãããæåãªIE6ã®ãã°ã¨è¨ããã件
å人çã«ã¯IE6ãªãã¦ãã対å¿ããæ°ããªããã ãã©ãããããåãã«ããããããã£ãã®ã§ãæ¤è¨¼ã³ã¼ããæ¸ãã¦ã¿ããããã§ãåç¾ããã®ã§ãããã¯jQueryã®ãã°ãã¨æãå ±åãã¦ã¿ãã(closed bug: cantfix)ãé ãã¾ããã
This is a well-known issue with IE6 being unable to update options, and can be fixed with setTimeout or one of the solutions suggested in the links below:
#11564 ($('option').attr('selected', true) does not work on IE6) – jQuery - Bug Tracker
well-known issueã¨ããäºã§ãå²ã¨ç¥ããã¦ãIE6ã®ãã°ï¼ã¿ãããæ¤è¨¼ã³ã¼ãã§ãåç¾ããããã¨ãã£ã¦ãããã«ãã°å ±åããªãã§ãã©ã¼ã©ã ã«ã¾ãæ¸ãã¹ãã ã£ããããªãã
ã¡ãªã¿ã«ãããã°ã«æ¸ãã®ããã£ããã§ãå ±åããã®ã¯ãã3ã¶æãåã¿ããã§ãã
å 容
jQuery+IE6ã®çµã¿åããã§ãJavaScriptã¨ã©ã¼ãçºçãã¾ãã
<form id="foo"> <select name="foo"> </select> <button>run</button> </form>http://jsfiddle.net/dmethvin/SVTUm/
optionè¦ç´ ã¯jQueryã§çµã¿ç«ã¦ãã¤ããã§ãoptionè¦ç´ ãæããªãselectè¦ç´ ãhtmlã«æ¸ãã¦ã¾ãã
$(function(){ $('button').click(function(e){ e.preventDefault(); var $select = $(this.form).find("select").empty(); var array = ['ein', 'zwei', 'drei']; for( var i=0; i<array.length; i++ ){ var $option = $('<option>'); $option.val('').text(array[i]); $select.prepend($option); } $select.children(':first').prop('selected', true); }); });​http://jsfiddle.net/dmethvin/SVTUm/
ããã¦jQueryã§optionè¦ç´ ãããã¤ã追å ããã©ãããselectedã«ãããã¨ããã¨ã»ã»ã»IE6éå®ã§JavaScriptã¨ã©ã¼ãçºçãã¾ãã>=IE7*1ããã®ä»ã®ã¢ãã³ãã©ã¦ã¶ã§ã¯çºçãã¦ã¾ããã
解決æ¹æ³
$(function(){ $('button').click(function(e){ e.preventDefault(); var $select = $(this.form).find("select").empty(); var array = ['ein', 'zwei', 'drei']; for( var i=0; i<array.length; i++ ){ var $option = $('<option>'); $option.val('').text(array[i]); $select.prepend($option); } setTimeout( function() { $select.children(':first').prop('selected', true); }, 1); }); });​http://jsfiddle.net/dmethvin/SVTUm/1/
setTimeout()ã§éåæå¦çã«ããã¨åé¿ã§ããããã§ãã
Because it is a timing issue it can't be fixed within jQuery core without introducing even more issues (e.g., what if other things run before we select the option in the timeout?)
#11564 ($('option').attr('selected', true) does not work on IE6) – jQuery - Bug Tracker
è±æèªè§£åã足ããã«ãæå³ãå®å ¨ã«æ±²ã¿åãã¦ãªããã§ãããããã¯ã¿ã¤ãã³ã°ã®åé¡ããããæ示ãããstack over flowãèªãã§ã¿ãã¨ãJavaScriptã§çæããè¦ç´ ã«JavaScriptãã¢ã¯ã»ã¹ããå ´åã®ãçæã¨ã¢ã¯ã»ã¹ã®ã¿ã¤ãã³ã°ã®äºãè¨ã£ã¦ããããªæ°ããã¾ããã
è£è¶³
<form id="bar"> <select name="bar"> <option value="">dummy</option> </select> <button>run</button> </form>​http://jsfiddle.net/dmethvin/SVTUm/
optionè¦ç´ ãæåããå
¥ãã¦ããã°ããã¨ãããã$().empty()
ã§æ¶ãã¦ãæ¹ãã¦optionè¦ç´ ãç©ãã ã¨ãã¦ããã¨ã©ã¼ã¯çºçãã¾ããã§ããã
jsdo.it
ãã£ãããJSFiddleããã°ããè²¼ã£ã¦ããã©ãæåã¯jsdo.itã§æ¤è¨¼ã³ã¼ãæ¸ãã¦ããã ããã
The site jsdo.it does not work for me in IE6. This JSFiddle reproduces the issue:
#11564 ($('option').attr('selected', true) does not work on IE6) – jQuery - Bug Tracker
jsdo.itã£ã¦ãUIè±èªã«ãã¦ããæµ·å¤ã§ããããã使ããã¦ãã®ããªã¼ã¨ãæã£ããã ãã©ããåããªãããJSFiddleã§ä½ããªããããã£ã¦è¨ããã¦ãã¾ãã¾ããã
http://jsfiddle.net/dmethvin/SVTUm/
http://jsfiddle.net/dmethvin/SVTUm/1/
確ãã«ãã®JSFiddleã¯ãSaveãã度ã«URLãçºè¡ããã¦ãã¡ãã£ã¨ãããã¼ã¸ã§ã³ç®¡çã¿ãããªæãã«ãªã£ã¦ã¦ä¾¿å©ãããä»åã®ãåããªãã³ã¼ãã¨ãç´ããã³ã¼ããã¹ãããªã¨ãã¦ããããã ãã¾ã¡ãã£ã¦Saveãã¡ãã£ã¦ããURLã®ã«ã¦ã³ãã¢ããã¯åãæ¶ããªãã¿ããã