当前位置:K88软件开发文章中心编程语言AjaxAjax01 → 文章内容

利用prototype.js来兼容FF和IE基础简例

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 9:22:24

在编写ajax程序的时候,会出现“在IE中运行正常,到FF中运行的效果改变了,或者在FF运行的效果是正确的,在IE中效果不正确或出现了错误,现在可以用prototype.js来兼容FF和IE”
prototype.js源码下载地址:http://www.aspprogram.cn/soft.asp?id=32

1、document.all.item的替换方式: 

document.all.item(&
#39
id_name&
#39
).className=&
#39
class_name&
#39
 

替代方式1: 

document.all.id_name.className=&
#39
class_name&
#39
 

替代方式2: 

$(&
#39
id_name&
#39
).className=&
#39
class_name&
#39

 


2、 
取得value值 

var 
temp 

document.all.item(&
#39
id_name&
#39
).value 

替代方式: 

var 
temp 

$F(&
#39
id_name&
#39
)
 


3、 
写入value值 

表单中写值 

$(form_name.id_name).value 

temp 

 

表单外写值 

$(id_name).value 

temp 

 

这样写是错误的:(错误说明:不能给对象的返回值赋值) 

$F(&
#39
id_name&
#39


temp 

 


4、写入className(class_name可为多个用空格分开) 

Element.addClassName(&
#39
id_class&
#39
,&
#39
class_name&
#39
)
 


5、移除className(class_name只能为单一) 

Element.removeClassName(&
#39
id_class&
#39
,&
#39
class_name&
#39
)
 


6、 
JS中变量名称于能与id_name重复 


7、 
例: 

<
li 
id="
huabei"
 
onMouseDown="
javascript:ctlist(event,&
#39
huabei&
#39
)"
 

class="
li"
>
测试<
/li>
 

function 
ctlist(evt,ct)
{} 

8、<

href="
javascript:toc(null,&
#39
测试&
#39
)"
 
class="
searcha"
>
测试<
/a>
 

function 
tos(evt,temp)


$(&
#39
searchkey&
#39
).value 

temp
 
//searchkey是在表单中的id 



9、 
FF下alert()是错误的. 
错误:没有足够的参数 


10、 
千万不能缺少id 


11、 
FF对js缓存清除困难,每次更新后最好重新打开一个FF 


12、 
识别浏览器 

var 
the_browser_name 

navigator.appName 

 

if(the_browser_name 
== 
"
Microsoft 
Internet 
Explorer"
)


alert("
你使用的是IE"
)
 



if(the_browser_name 
== 
"
Netscape"
)


alert("
你使用的是FF"
)
 




<
SCRIPT 
LANGUAGE="
JavaScript"
>
 

<
!-- 

var 
the_browser_name 

navigator.appName 


 
if(the_browser_name 
== 
"
Microsoft 
Internet 
Explorer"
)



alert("
你使用的是IE"
)
 



if(the_browser_name 
== 
"
Netscape"
)



//(这段有错吧?) 

alert("
你使用的是FF"
)

 


//-->
 
<
/SCRIPT>
 



利用prototype.js来兼容FF和IE基础简例