IE9 以下常常要做一些特別的處理 稍微整理一下
1. input, textarea 的 "placeholder" 屬性,IE10 以上才支援,建議偵測 IE9 以下版本時,特別跑 js 用 onfocus, onblur 來處理
function setPlaceholder(e) { var placeholder = $(this).attr('placeholder'); if ($(this).val().length == 0) { $(this).css("color", "#b2b2b2").val(placeholder); } $(this).focus(function (e) { if ($(this).val() == placeholder) { $(this).css("color", "#666").val(""); } }); $(this).blur(function (e) { if ($(this).val().length == 0) { $(this).css("color", "#b2b2b2").val(placeholder); } }); } if (Is_LTE_IE9) { $('input[placeholder]').each(setPlaceholder); $('textarea[placeholder]').each(setPlaceholder); }
2. <input type=file /> 不能用 js 去 click,必須要user真的去點他, js 才抓得到檔案,不然傳到server也是空的
3. IE9 的 js console.log 必須在 "偵錯模式" 下才能使用,所以js程式完成後,要記得把 console.log 清掉或是註解掉
不然一般 IE9 的 User 會跳出 js 的錯誤,然後 js 就停了。(這個問題必須在純IE9的瀏覽器才能發現,IE10模擬IE9也發 現不到)
4. Firefox 問題: 當我們要算div的寬高時,他本身必須 display:block 才能算的出來,不然會是 0,
但是 Firefox 連隱藏iframe 裡的 html > div 都會回傳 0,必須把 iframe 設為 display:block;visibility:hidden
才能算出裡面div的寬高