首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

这个自动提示框为什么在ff用不了解决办法

2012-03-23 
这个自动提示框为什么在ff用不了ie正常ff就不正常scriptlanguage javascript varClass{create:funct

这个自动提示框为什么在ff用不了
ie正常ff就不正常

<script   language= "javascript ">
var   Class   =   {
    create:   function()   {
        return   function()   {
            this.initialize.apply(this,   arguments);
        }
    }
}

Object.extend   =   function(destination,   source)   {
    for   (var   property   in   source)   {
        destination[property]   =   source[property];
    }
    return   destination;
}

var   PromptList   =   Class.create();
PromptList.prototype   =   Object.extend(Object,   {
    initialize:   function(arrList,   idText,   idDiv)   {
this.aList   =   arrList.sort(this.SetSort);
this.oText   =   document.getElementById(idText);
this.oDiv   =   document.getElementById(idDiv);
var   o   =   this;
this.oText.onblur   =   function(){   PromptList.prototype.Hide.call(o)   };
this.oText.onkeyup   =   function(){   PromptList.prototype.Keyup.call(o)   };
this.oText.onfocus   =   function(){   PromptList.prototype.Show.call(o)   };
this.iIndex   =   -1;
    },
    //隐藏Div
    Hide   :   function(){
this.oDiv.style.display   =   'none ';
    },
    //排序函数
    SetSort:   function(a,   b){
if   (a.length   >   b.length)   return   1;
else   if   (a.length   ==   b.length)   return   a.localeCompare(b);
else   return   -1;
    },
    //检查Div
    CheckDiv:   function(){
if   (0   <   this.oDiv.children.length)   {   return   true;   }   else   {   this.Hide();   return   false;}
    },
    //输出
    Output   :   function(){
if(this.iIndex   > =   0){
this.oText.value   =   this.stripTags(this.oDiv.children[this.iIndex].innerHTML);
}
this.Hide();
    },
    //检查按键
    Keyup   :   function(e){
var   keyCode   =   (document.all)   ?   window.event.keyCode   :   e.charCode;
if   (keyCode   ==   40   ||   keyCode   ==   38){   //下上
var   isUp   =   (keyCode   ==   40)   ?   true   :   false;
if   (this.CheckDiv())   {   this.Move(isUp);   }
}else   if   (keyCode   ==   13){
this.Output();//回车
}else{   this.Show()   }
    },
    //检查显示
    Show   :   function(){
var   sValue   =   this.oText.value;
if   (sValue){
this.iIndex   =   -1;
this.oDiv.innerHTML   =   " ";
for   (var   i   =   0;   i   <   this.aList.length;   i++){
if(this.aList[i].toUpperCase().indexOf(sValue.toUpperCase())   > =   0){
this.Add(this.aList[i].replace(sValue,   " <font   color=\ "#FF0000\ "> "+sValue+ " </font> "));


}
}
if   (this.CheckDiv())   {   this.SetDiv();   this.oDiv.style.display   =   ' ';   }
}else{   this.Hide();   };
    },
    //插入选项
    Add   :   function(sValue){
var   oNewDiv   =   document.createElement( "div ");
var   o   =   this;
with(oNewDiv){
style.width   =   this.oText.offsetWidth;
onmouseover   =   function(){   PromptList.prototype.MouseMove.call(o,   oNewDiv)   };
onmousedown   =   function(){   PromptList.prototype.Output.call(o)   };
innerHTML   =   sValue;
}
this.oDiv.appendChild(oNewDiv);
    },
    //上下键选择
    Move   :   function(isUp){
if   (this.oDiv.style.display   ==   'none '){
this.oDiv.style.display   =   ' ';
}else{
if   (isUp)   {   this.iIndex++   }   else   {   this.iIndex--   };
}
var   maxIndex   =   this.oDiv.children.length-1;
if   (this.iIndex   <   0)   {   this.iIndex   =   0   };
if   (this.iIndex   >   maxIndex)   {   this.iIndex   =   maxIndex   };
this.Selected();
    },
    //鼠标选择
    MouseMove   :   function   (o){
    var   maxIndex   =   this.oDiv.children.length-1;
for   (var   i   =   0;   i   <=   maxIndex;   i++)
if(this.oDiv.children[i]   ==   o){   this.iIndex   =   i;   break;   };
this.Selected();
    },
    //显示选择项
    Selected   :   function(){
var   maxIndex   =   this.oDiv.children.length-1;
for   (var   i   =   0;   i   <=   maxIndex;   i++)
this.oDiv.children[i].className= " ";
this.oDiv.children[this.iIndex].className= "selectedStyle ";
    },
    //设置Div
    SetDiv   :   function   (){
this.oDiv.style.top   =   this.oText.offsetHeight   +   this.Top();
this.oDiv.style.left   =   this.Left();  
this.oDiv.style.width   =   this.oText.offsetWidth;
    },
    Left   :   function(){
var   o   =   this.oText;
var   iLeft   =   o.offsetLeft;
while(   o   !=   null   &&   o.offsetParent   !=   null   &&   o.offsetParent.tagName   !=   "BODY "   ){
iLeft   +=   o.offsetParent.offsetLeft;
o   =   o.offsetParent;
}
return   iLeft   ;
    },
    Top   :   function(){
var   o   =   this.oText;
var   iTop   =   o.offsetTop;
while(   o   !=   null   &&   o.offsetParent   !=   null   &&   o.offsetParent.tagName   !=   "BODY "   ){
iTop   +=   o.offsetParent.offsetTop;
o   =   o.offsetParent;
}
return   iTop   ;
    },
    //去除标签
    stripTags:   function(sValue)   {
        return   sValue.replace(/ <\/?[^> ]+> /gi,   ' ');


    }
});
</script>

<body>
<table   align= "center ">
<tr> <td>
<input   type= "text "   id= "inputer ">
</td> </tr>
</table>
</body>

<style>
.selectedStyle{background-Color:#102681;color:#FFFFFF}
</style>
<div   id= 'DivList '   style= 'position:absolute;display:none;background:#E8F7EB;border:   1px   solid   #CCCCCC;font-size:14px;cursor:   hand; '>   </div>

<script>
var   arrList   =   new   Array();
var   intIndex=0;
arrList[intIndex++]   =   "1sdfsdf.m ";
arrList[intIndex++]   =   "111sdafs.net ";
arrList[intIndex++]   =   "b22d1df ";
arrList[intIndex++]   =   "c333a1safffffffffffffffffffffdf ";
new   PromptList(arrList, "inputer ",   "DivList ");
</script>

[解决办法]
ff-> 工具-> 错误控制台 看看错误

热点排行