1.document.formName.item("itemName") ÎÊÌâ
˵ Ã÷:IEÏÂ,¿ÉÒÔʹÓÃdocument.formName.item("itemName")»òdocument.formName.elements ["elementName"];FirefoxÏÂ,Ö»ÄÜʹÓÃdocument.formName.elements["elementName"].
½â¾ö·½·¨:ͳһʹÓÃdocument.formName.elements["elementName"].
2.¼¯ºÏÀà¶ÔÏóÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓÃ()»ò[]»ñÈ¡¼¯ºÏÀà¶ÔÏó;FirefoxÏÂ,Ö»ÄÜʹÓÃ[]»ñÈ¡¼¯ºÏÀà¶ÔÏó.
½â¾ö·½·¨:ͳһʹÓÃ[]»ñÈ¡¼¯ºÏÀà¶ÔÏó.
3.×Ô¶¨ÒåÊôÐÔÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓûñÈ¡³£¹æÊôÐԵķ½·¨À´»ñÈ¡×Ô¶¨ÒåÊôÐÔ,Ò²¿ÉÒÔʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ;FirefoxÏÂ,Ö»ÄÜʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ.
½â¾ö·½·¨:ͳһͨ¹ýgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ.
4.eval("idName")ÎÊÌâ
˵Ã÷:IEÏÂ,,¿ÉÒÔʹÓÃeval("idName")»ògetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó;FirefoxÏÂÖ»ÄÜʹÓÃgetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó.
½â¾ö·½·¨:ͳһÓÃgetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó.
5.±äÁ¿ÃûÓëijHTML¶ÔÏóIDÏàͬµÄÎÊÌâ
˵Ã÷:IEÏÂ,HTML¶ÔÏóµÄID¿ÉÒÔ×÷ΪdocumentµÄÏÂÊô¶ÔÏó±äÁ¿ÃûÖ±½ÓʹÓÃ;FirefoxÏÂÔò²»ÄÜ.FirefoxÏÂ,¿ÉÒÔʹÓÃÓëHTML¶ÔÏ ......
var docEle = function() {
return document.getElementById(arguments[0]) || false;
}
function cloDiv(){
var overlayID="overlay";
var msgID = "overlayMsg";
document.body.removeChild(docEle(overlayID));
document.body.removeChild(docEle(msgID));
}
function openNewDiv() {
var overlayID="overlay";
var msgID = "overlayMsg";
if (docEle(overlayID)) document.removeChild(docEle(overlayID));
if (docEle(msgID)) document.removeChild(docEle(msgID));
// ÏûÏ¢ÏÔʾ
var newDiv = document.createElement("div");
newDiv.id = msgID;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "999";
newDiv.style.width = "200px";
newDiv.style.height = "30px";
var scrolltop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
var _clientheight=0;
//ie FF ÔÚÓÐDOCTYPEʱ¸÷ÓÐÇø±ð
_clientheight = Math.min(document.body.clientHeight , document.documentElement.clientHeight);
......
ÖÆ×÷ÍøÒ³µÄ¹ý³ÌÖУ¬ÄãÓÐʱºòÐèÒªÖªµÀij¸öÔªËØÔÚÍøÒ³ÉϵÄÈ·ÇÐλÖá£
ÏÂÃæµÄ½Ì³Ì×ܽáÁËJavascriptÔÚÍøÒ³¶¨Î»·½ÃæµÄÏà¹Ø֪ʶ¡£
Ò»¡¢ÍøÒ³µÄ¾ø¶Ô´óСºÍÏà¶Ô´óС
Ê×ÏÈ£¬ÒªÃ÷È·Á½¸ö»ù±¾¸ÅÄî¡£
Ò»ÕÅÍøÒ³µÄÈ«²¿Ãæ»ý£¬¾ÍÊÇËüµÄ¾ø¶Ô´óС¡£Í¨³£Çé¿öÏ£¬ÍøÒ³µÄ¾ø¶Ô´óСÓÉÄÚÈݺÍCSSÑùʽ±í¾ö¶¨¡£
ÍøÒ³µÄÏà¶Ô´óСÔòÊÇÖ¸ÔÚä¯ÀÀÆ÷´°¿ÚÖп´µ½µÄÄDz¿·ÖÍøÒ³£¬Ò²¾ÍÊÇä¯ÀÀÆ÷´°¿ÚµÄ´óС£¬ÓÖ½Ð×öviewport£¨ÊÓ¿Ú£©¡£
ÏÂͼÖÐÑëµÄ·½¿ò¾Í´ú±íä¯ÀÀÆ÷´°¿Ú£¬Ã¿´ÎÖ»ÄÜÏÔʾһ²¿·ÖÍøÒ³¡£
£¨Í¼Ò» ÍøÒ³µÄ¾ø¶Ô´óСºÍÏà¶Ô´óС£©
ºÜÏÔÈ»£¬Èç¹ûÍøÒ³µÄÄÚÈÝÄܹ»ÔÚä¯ÀÀÆ÷´°¿ÚÖÐÈ«²¿ÏÔʾ£¨Ò²¾ÍÊDz»³öÏÖ¹ö¶¯Ìõ£©£¬ÄÇôÍøÒ³µÄ¾ø¶Ô´óСºÍÏà¶Ô´óСÊÇÏàµÈµÄ¡£
¶þ¡¢»ñÈ¡ÍøÒ³µÄÏà¶Ô´óС
ÍøÒ³ÉϵÄÿ¸öÔªËØ£¬¶¼ÓÐclientHeightºÍclientWidthÊôÐÔ£¬ÀûÓÃËüÃǾͿÉÒԵõ½ÍøÒ³µÄÏà¶Ô´óС¡£ÕâÁ½¸öÊôÐÔ´ú±íµÄ´óС£¬ÊÇÖ¸ÔªËصÄÄÚÈݲ¿·ÖÔÙ¼ÓÉÏpaddingµÄ´óС£¬µ«ÊDz»°üÀ¨borderºÍ¹ö¶¯ÌõÕ¼ÓõĿռ䡣
£¨Í¼¶þ clientHeightºÍclientWidthÊôÐÔ£©
Òò´Ë£¬documentÔªËصÄclientHeightºÍclientWidthÊôÐÔ£¬¾Í´ú±íÁËÍøÒ³µÄÏà¶Ô´óС¡£
¡¡¡¡function getViewport(){
¡¡¡¡¡¡¡¡if (document.compatMode == "BackCompat"){
¡¡¡¡¡¡¡¡¡¡¡¡return {
......
½â¾öFirefox ÏÂF5ºÍIEÏÂF5 ²»Ò»ÖµÄjavascript ½Å±¾.
var check=function(e)
{
e=e||window.event;
//alert(e.which||e.keyCode);
if((e.which||e.keyCode)==116)
{
if(e.preventDefault)
{ e.preventDefault();}
else
{
event.keyCode = 0;
e.returnValue=false;
}
window.location.href = this.location.href;
}
}
if(document.addEventListener){
document.addEventListener("keydown",check,false);
}
else{
document.attachEvent("onkeydown",check);
} ......
¼ÙÉè obj Ϊij¸ö HTML ¿Ø¼þ¡£
obj.offsetTop Ö¸ obj ¾àÀëÉÏ·½»òÉϲã¿Ø¼þµÄλÖã¬ÕûÐÍ£¬µ¥Î»ÏñËØ¡£
obj.offsetLeft Ö¸ obj ¾àÀë×ó·½»òÉϲã¿Ø¼þµÄλÖã¬ÕûÐÍ£¬µ¥Î»ÏñËØ¡£
obj.offsetWidth Ö¸ obj ¿Ø¼þ×ÔÉíµÄ¿í¶È£¬ÕûÐÍ£¬µ¥Î»ÏñËØ¡£
obj.offsetHeight Ö¸ obj ¿Ø¼þ×ÔÉíµÄ¸ß¶È£¬ÕûÐÍ£¬µ¥Î»ÏñËØ¡£
ÎÒÃǶÔÇ°ÃæÌáµ½µÄ“ÉÏ·½»òÉϲã”Óë“×ó·½»òÉϲ㔿ؼþ×÷¸ö˵Ã÷¡£
ÀýÈ磺
<div id="tool">
<input type="button" value="Ìá½»">
<input type="button" value="ÖØÖÃ">
</div>
“Ìá½»”°´Å¥µÄ offsetTop Ö¸“Ìá½»”°´Å¥¾à“tool”²ãÉϱ߿òµÄ¾àÀ룬ÒòΪ¾àÆäÉϱß×î½üµÄÊÇ “tool” ²ãµÄÉϱ߿ò¡£
“ÖØÖÔ°´Å¥µÄ offsetTop Ö¸“ÖØÖÔ°´Å¥¾à“tool”²ãÉϱ߿òµÄ¾àÀ룬ÒòΪ¾àÆäÉϱß×î½üµÄÊÇ “tool” ²ãµÄÉϱ߿ò¡£
“Ìá½»”°´Å¥µÄ offsetLeft Ö¸“Ìá½»”°´Å¥¾à“tool”²ã×ó±ß¿òµÄ¾àÀ룬ÒòΪ¾àÆä×ó±ß×î½üµÄÊÇ “tool” ²ãµÄ×ó±ß¿ò¡£
&l ......
ÓÃJavaScriptÒþ²Ø¿Ø¼þµÄ·½·¨ÓÐÁ½ÖÖ£¬·Ö±ðÊÇͨ¹ýÉèÖÿؼþµÄstyleµÄ“display”ºÍ“visibility”ÊôÐÔ¡£µ±style.display="block"»òstyle.visibility="visible"ʱ¿Ø¼þ»ò¼û£¬µ±style.display = "none"»òstyle.visibility = "hidden"ʱ¿Ø¼þ²»¿É¼û¡£²»Í¬µÄÊÇ“display”²»µ«Òþ²Ø¿Ø¼þ£¬¶øÇÒ±»Òþ²ØµÄ¿Ø¼þ²»ÔÙÕ¼ÓÃÏÔʾʱռÓõÄλÖ㬶ø“visibility”Òþ²ØµÄ¿Ø¼þ½ö½öÊǽ«¿Ø¼þÉèÖóɲ»¿É¼ûÁË£¬¿Ø¼þÈÔȻռ¾ãÔÀ´µÄλÖá£
<p>
<input id='control' value="ÏëÒªÒþ²ØµÄ¿Ø¼þ">
</p>
<p>
Òþ²ØÉÏÃæµÄ¿Ø¼þ£¬²¢Ê¹Æä²»Õ¼ÓÃÒ³ÃæÉϵÄλÖÃ
<input type="button" value='Òþ²Ø' onclick='displayHide_control()'>
<input type="button" value='ÏÔʾ' onclick='displayShow_control()'>
<br />
½ö½öÒþ²Ø¿Ø¼þ£¬ÆäλÖÃÈÔȻռÓÃ
<input type="button" value='Òþ²Ø' onclick='visibilityHide_control()'>
<input type="button" value='ÏÔʾ' onclick='visibilityShow_control()'>
</p>
<script language="javascript" type="text/javascript">
function displayHide_control()
{
......