⑴ CSS+js更改alert的默認對話框
functionalert(){
document.getElementById('alertBox').style.display="unset";
return;
}
然後自己設定id=alertBox的樣式即可(劇中代碼內:)容
#alertBox{
position:fixed;
left:50%;
top:50%;
transform:translate(-50%,-50%);
z-index:999;
}
⑵ javascript能重載document.getElementById()方法嗎
貌似不能,js的方法是不能重載的,因為js是弱類型的,方法的參數列表以及類型和返回類型都是未知的。
比如定義一個方法 function fun(){return argments[0] + argments[1];}
而調用的時候,可以這樣寫var a = fun(1 , 2); 也可以這樣寫 var a=fun();
你只能以擴展的方式,自己寫個getElementById方法,先把document.getElementById包裝一下,再做其它的事。。
⑶ javaScript中的alert()問題
我感覺應該是$.post用的非同步方式的原因。
執行順序應該是這樣的:yzCard -> alert("方法外面"+falg); 這里線程就阻塞了
非同步線程 -> 執行 $.post -> alert("data:" + data); -> alert("flag=true後面:" + falg);
這個 alert("方法外面"+falg) 應該是第一個彈出的,只不過你的 $.post裡面的代碼是非同步執行的,覆蓋的這個alert,當你點擊完$.post 裡面的兩個alert 才看到 alert("方法外面"+falg) 。然後點擊確認後 才開始執行後面的if(falg==true)
由於$.post 裡面的代碼已經將falg 置為true 了 所有 就出現了 alert("這是個if判斷,這說明falg=true");
⑷ 在javascript中,alert()是什麼意思請具體介紹一下吧!謝謝
alert在英語中的意思是警告,javascript中,alert()是彈出警告框的意思。
⑸ javaScript中怎麼設置」來自網頁的消息「如圖:
直接重寫window.alert; 用自己的樣式實現
window.alert=function(str)
{
varshield=document.createElement("DIV");
shield.id="shield";
shield.style.position="absolute";
敏嘩御shield.style.left="0px";
shield.style.top="0px";
shield.style.width="100%";
shield.style.height=document.body.scrollHeight+"px";
//彈出對話框時的背景顏色
shield.style.background="#fff";
shield.style.textAlign="center";
shield.style.zIndex="25";
//背景透明IE有效
//shield.style.filter="alpha(opacity=0)";
varalertFram=document.createElement_x("DIV");
alertFram.id="alertFram";
alertFram.style.position="absolute";
alertFram.style.left="50%";
alertFram.style.top="50%";
alertFram.style.marginLeft="-225px";
alertFram.style.marginTop="-75px";
alertFram.style.width="450px";
alertFram.style.height="150px";
alertFram.style.background="#ff0000";
alertFram.style.textAlign="center";
alertFram.style.lineHeight="150px";
alertFram.style.zIndex="300";
strHtml="<ulstyle="list-style:none;margin:0px;padding:0px;width:100%"> ";
strHtml+="<listyle="background:#DD828D;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1pxsolid#F9CADE;">[自定義提示]</li> ";
strHtml+="<listyle="background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1pxsolid#F9CADE;border-right:1pxsolid#F9CADE;">"+str+"</li> ";
strHtml+="<listyle="background:#FDEEF4;text-align:center;font-weight:bold;height:25px;line-height:25px;border:1pxsolid#F9CADE;"><inputtype="button"value="確定"onclick="doOk()"/></li> ";
strHtml+="</ul> ";
alertFram.innerHTML=strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(shield);
varad=setInterval("doAlpha()",5);
this.doOk=function(){
alertFram.style.display="none";
shield.style.display="none";
橋岩}
alertFram.focus();
蘆漏document.body.onselectstart=function(){returnfalse;};
}
在自定義提示那裡替換你的提示
⑹ 如何重寫js的alert方法
window.alert=function(msg){
//addyourcodehere
}
⑺ javascript問題,關於重構window.alert()後,然後調用window原本的window.alert()的方法
我的理解是這樣的。
window._alert=window.alert//臨時保存一下;
window.alert=function(){
//寫你重構的方法;
return;
}
//下面你想恢復回的話就答很簡單了
window.alert=window._alert;
⑻ 如何重寫 alert,confirm,prompt-CSDN論壇
這個Jquery插件的目的是替代JavaScript的標准函數alert(),confirm(),和 prompt()。這個插件有如下這些特點:
1:這個插件可以使你可以支持你自己的css制定。使你的網站看起來更專業。
2:允許你自定義對話框的標題。
3:在IE7中,可以使你避免使用JavaScript 的prompt()函數帶來的頁面重新載入。
4:這些方法都模擬了Windows的模式對話框。在你改變改變瀏覽器窗口大小時候,它能夠自適應用戶
窗口的調整。
5:如果你引入了jQuery UI Draggable plugin插件,那這個插件也可以被自由拖動。
jquery.alerts.js代碼:
// Download by http://keleyi.com
// 由 柯樂義 改進改插件,使插件適用於新版的jquery(比如1.10.1) 版本
// Visit http://keleyi.com/a/bjac/no0m3cb1.htm for more information
//
// Usage:
// jAlert( message, [title, callback] )
⑼ JS什麼情況下需要重寫方法或屬性
因為現在流行面向對象的開發思想,也可以斗穗理解空悄卜為對象中的方法或屬性都是從父類繼承過來的,當對象需要實現一些父類現有的方法運旅不能滿足的邏輯任務時,正確的做法應該是擴展父類的屬性或方法,而不是重新定義。