FF IE兼容性的修改小結
2024-05-06 14:14:09
供稿:網友
1.html 標簽如果用 $(id) 或者 getElementById 這兩個方法取值時,要給該標簽加上 id 的屬性, IE 、 FF 才兼容。如 $(mobile): 如果填 寫 mobile 的 input 沒有 id 屬性在 FF 中會報這個變量 undefined ;
2. 取 form 表單的某個標簽對象,如果要 IE 、 FF 兼容要把 formMain.item 改為 document.formName.item 。
如 form1.webUrl 改為 document.form1.webUrl 。
如果 form 作為一個參數傳給某個函數,也要加上 "document.", 如 search(formMain) 改為 search(document.formMain)
3. 取 html 的自定義屬性用 obj.attributeName 改為 obj.getAttribute("attributeName") 取則 IE 、 FF 兼容;非自定義屬性仍可以按照
obj.attributeName 取。
如: <input type="text" name="memberCn" checkValue="notNull;eLength:25"> 這個標簽中的 checkValue 屬性為自定義屬性,要用 obj.getAttribute("checkValue") 取, IE 、 FF 才兼容,其他屬性如 type 屬性則仍然可以用 obj.type 取
4.eval 函數,在 FF 和 IE 中使用不一樣 , 在 FF 中用“ + ”連接成的一個可執行語句作為 eval 的參數時,不能執行而在 IE 中可以。遇到 要用 eval 時,盡量找別的方法代替。
如: eval("msg_" + textbox.name+ “ .className='wrong' ”) ;
"msg_" + textbox.name+ “ .className='wrong' ”這句話作為 eval 的參數在 IE 中能執行,在 FF 中執行時報 "msg_" + textbox.name 連接得到的空間名 undefined ,不能執行, 要修改為:
document.getElementById("msg_" + textbox.name).className='wrong';
5. 樣式中的 display 的屬性 block ,在 FF 中如果遇到異常可以變為空;如 item.style.display="block" 可以改為 item.style.display=""
如 $("divType4").style.display="block";
改為 $("divType4").style.display="";
6. 再添加一個: label 在 FF 中好像跟 IE 不一樣:比如說以下代碼:
<td colspan = "3" class = "line_l"> 成人 <label>
<input name = "amount" type = "text" value = "${amount} " size = "6" maxlength = "10" eleName = "[ 成人預訂人數 ]" checkValue = "notNull;eLength:10;isLong" />
人 兒童
<input name = "kidAmount" type = "text" value = "${kidAmount} " size = "6" maxlength = "10" eleName = "[ 兒童預訂人數 ]" checkValue = "notNull;eLength:10;isLong" />
人 <span class = "line_red"> * </ span></label>
</ td>
這樣寫在 FF 中輸入時兒童的光標總是跑到成人那里去, IE 中不會,而這樣寫就不會:
<td width = "25%"> 成人 <label>
<input name = "amount" type = "text" value = "${amount} " size = "6" maxlength = "10" eleName = "[ 成人預訂人數 ]" checkValue = "notNull;eLength:10;isLong" /> 人 </ label></ td>
<td width = "75%"> 兒童 <label><input name = "kidAmount" type = "text" value = "${kidAmount} " size = "6" maxlength = "10" eleName = "[ 兒童預訂人數 ]" checkValue = "notNull;eLength:10;isLong" /> 人 </ label></ td>