以下程式碼在IE8下運行通過,在IE9中出錯: 複製程式碼 程式碼如下: 程式碼如下:document.createElement('');錯誤提示:exception : SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5) 思路分析:第一步:相容於IE9,firefox,Opera,Safari等瀏覽器; 複製程式碼 程式碼如下:var iframe = document.createElement("iframe"); iframe.setAttribute("id", "yui-history-iframe");iframe.setAttribute("src", "../../images/defaults/transparent-pixel.gif"); iframe.setAttribute("style","position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;"); 第二步:兼容IE6-8:由於ie6-8 不能修改iframe的name屬性 複製代碼 程式碼如下: var oFrame = isIE ? document.createElement("") : document.createElement("iframe"); oFrame.name = "iframName"; 綜合解決方法: 複製程式碼 程式碼如下: var isIE = (document.all) ? true: false; //这里仅仅简单的对是否是IE进行判断,详细浏览器判断:请参考浏览器类型侦测var ua = navigator.userAgent.toLowerCase().match(/msie ([/d.] + ) / )[1];if (ua == "9.0") { isIE = false;}var oFrame = isIE ? document.createElement("") : document.createElement("iframe");oFrame.name = "iframName";//=========================function ajaxpost(formid, showid, waitid, showidclass, Submitbtn, recall) { var waitid = typeof waitid == 'undefined' || waitid === null ? '' : showidclass; var ajaxframeid = 'ajaxframe'; var ajaxframe = $(ajaxframeid); tion( ){var s ='';var evaled = false;showloading('none''); s = $(ajaxframeid).contentwindow.document .XMLDocument.text; 🎜 > 嘗試 { } catch (e) { > } } } evalscript(s); 評估= true; } if (submitbtn) { Submitbtn.disabled =假; > } if (!evaled && (typeof ajaxerror == '未定義' || !ajaxerror)) { 🎜> ajaxerror = null; if ($(formid)) $(formid).target = formtarget; if (recall 模式 } else { eval (記憶); } if (!evaled) evalscript(s) ; ajaxframe.loading = 0; $('append_parent').removeChild(ajaxframe); ajaxframe =文件。 。 ajaxframe.name = ajaxframeid; ajaxframe.style.display = '無'; ajax 框架.loading = 1; $( 'append_parent').appendChild(ajaxframe); } else if (ajaxframe.loading) { return falsese return falsese; _attachEvent(ajaxframe, 'load', handleResult); &inajax=1'; $(formid).submit(); 回傳false;}