js 自定義提示框 適配火狐,谷歌,IE

 function PromptBox(id) {
     this.value="";
     this.shadowId=id;
     this.divId=id+1;
    this.div1Id=id+2;

};


PromptBox.prototype.createNewPromptBox=function () {
var scrollHeight=document.documentElement.scrollHeight+'px';
var scrollWidth=document.documentElement.scrollWidth+'px';
var body=document.body;

/*提示框陰影div*/
var div1=document.createElement("div");
div1.id=this.shadowId;
div1.style.position="absolute";
div1.style.background=" #000";
div1.style.zIndex="3001";
div1.style.left="0";
div1.style.top="0";
div1.style.opacity="0.6";
div1.style.display="none";
div1.style.height=scrollHeight;
div1.style.width=scrollWidth;

body.appendChild(div1);

/*-------------*/
var div9=document.createElement("div");
div9.id=this.divId;
div9.style.zIndex="3002";
div9.style.position="fixed";
div9.style.background=" #fff";
div9.style.left="0";
div9.style.top="0";
div9.style.bottom="0";
div9.style.right="0";
div9.style.width="400px";
div9.style.height="85px";
div9.style.display="none";
div9.style.borderRadius="4px";
div9.style.margin="auto";


/*   div9.style.display="none";*/


var div10=document.createElement("div");
div10.id=this.div1Id;
div10.style.padding="0 20px";
div10.style.overflow="hidden";
div10.style.height="42px";
div10.style.lineHeight="42px";
div10.style.color="#333";
div10.style.backgroundColor="#f8f8f8";
div10.style.cursor='move';
div10.style.textAlign="left";
div10.style.borderBottom="1px solid #eee";
div10.style.borderRadius="2px 2px 0 0";
div10.style.fontSize=" 14px";
div10.innerText=this.value;



var div11=document.createElement("div");
div11.style.borderTop="1px solid #2885d5";
div11.style.wordBreak="break-all";
div11.style.position="relative";
div11.style.overflowY="auto";
div11.style.overflowX="hidden";
div11.style.lineHeight="24px";
div11.style.textAlign="right";
div11.style.borderTop="1px solid #2885d5";
div11.style.fontSize="14px";


var input0=document.createElement("input");
input0.type="button";
input0.value="確認(rèn)";
input0.style.color="#FFF";
input0.style.background="#2885d5 none repeat scroll 0 0";
input0.style.padding="0 15px";
input0.style.margin="6px 6px 0";
input0.style.cursor="pointer";
input0.style.fontWeight="400";
input0.style.height="28px";
input0.style.lineHeight="28px";

var this_=this;
input0.onclick=function () {

    this_.closeNewPromptBox();
};
div11.appendChild(input0);

div9.appendChild(div10);
div9.appendChild(div11);
body.appendChild(div9);



/*alert(this.value.length);
alert(this_.getStyle());*/
 };
 PromptBox.prototype.getStyle=function () {
if(document.getElementById(this.div1Id).currentStyle){

    if( document.getElementById(this.div1Id).currentStyle['width']=="auto"){
        return this.value.length*15;
    }else{
        return document.getElementById(this.div1Id).currentStyle['width'];
    }
    /* return document.getElementById(this.div1Id).offsetWidth ;*/
}else{
    if(getComputedStyle(document.getElementById(this.div1Id),false)['width']=="auto"){
        return this.value.length*15;
    }else{
        return getComputedStyle(document.getElementById(this.div1Id),false)['width'];
    }

}
};
PromptBox.prototype.closeNewPromptBox=function () {
document.getElementById(this.shadowId).style.display="none";
document.getElementById(this.divId).style.display="none";
  };


 PromptBox.prototype.showNewPromptBox=function () {
var scrollHeight=document.documentElement.scrollHeight+'px';
var scrollWidth=document.documentElement.scrollWidth+'px';

document.getElementById(this.shadowId).style.height=scrollHeight;
document.getElementById(this.shadowId).style.width=scrollWidth;


var this_=this;
this.value=arguments[0];

document.getElementById(this.div1Id).innerText=this.value;

var  width="";
if(this_.getStyle()<400){
    width=400;
}else{
    width=this_.getStyle();
}
document.getElementById(this.divId).style.width=width+"px";
document.getElementById(this.shadowId).style.display="";
document.getElementById(this.divId).style.display="";

      };
  PromptBox.prototype.removeNewPromptBox=function () {
document.getElementById(this.shadowId).parentNode.removeChild(document.getElementById(this.shadowId));
document.getElementById(this.divId).parentNode.removeChild(document.getElementById(this.divId));
   };
    /*PromptBox.prototype.showNewPromptBox=function () {

alert(this.value);
document.getElementById('promptBox__Div_01').style.display='';
document.getElementById('promptBoxValue_Div_01').innerText=this.value;
document.getElementById('promptBox_shadow').style.display='';

document.getElementById('promptBox__Div_01').style.width=getStyle(document.getElementById("promptBoxValue_Div_01"),'width');

 };*/
   /*提示框確認(rèn)寡夹,就是關(guān)閉提示框*/

 //使用方法
  var promptBox=new PromptBox("new_prompt_box");
  promptBox.createNewPromptBox();
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市厂置,隨后出現(xiàn)的幾起案子菩掏,更是在濱河造成了極大的恐慌,老刑警劉巖昵济,帶你破解...
    沈念sama閱讀 222,252評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件智绸,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡访忿,警方通過(guò)查閱死者的電腦和手機(jī)瞧栗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,886評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)海铆,“玉大人迹恐,你說(shuō)我怎么就攤上這事∥哉澹” “怎么了殴边?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,814評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)珍语。 經(jīng)常有香客問(wèn)我锤岸,道長(zhǎng),這世上最難降的妖魔是什么板乙? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,869評(píng)論 1 299
  • 正文 為了忘掉前任是偷,我火速辦了婚禮,結(jié)果婚禮上募逞,老公的妹妹穿的比我還像新娘蛋铆。我一直安慰自己,他們只是感情好放接,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,888評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布戒职。 她就那樣靜靜地躺著,像睡著了一般透乾。 火紅的嫁衣襯著肌膚如雪洪燥。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 52,475評(píng)論 1 312
  • 那天乳乌,我揣著相機(jī)與錄音捧韵,去河邊找鬼。 笑死汉操,一個(gè)胖子當(dāng)著我的面吹牛再来,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 41,010評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼芒篷,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼搜变!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起针炉,我...
    開(kāi)封第一講書(shū)人閱讀 39,924評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤挠他,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后篡帕,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體殖侵,經(jīng)...
    沈念sama閱讀 46,469評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,552評(píng)論 3 342
  • 正文 我和宋清朗相戀三年镰烧,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了拢军。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,680評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡怔鳖,死狀恐怖茉唉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情结执,我是刑警寧澤度陆,帶...
    沈念sama閱讀 36,362評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站昌犹,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏览芳。R本人自食惡果不足惜斜姥,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,037評(píng)論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望沧竟。 院中可真熱鬧铸敏,春花似錦、人聲如沸悟泵。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,519評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)糕非。三九已至蒙具,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間朽肥,已是汗流浹背禁筏。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,621評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留衡招,地道東北人篱昔。 一個(gè)月前我還...
    沈念sama閱讀 49,099評(píng)論 3 378
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親州刽。 傳聞我的和親對(duì)象是個(gè)殘疾皇子空执,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,691評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容