javascript常用對話框小集
更新時間:2013年09月13日 17:16:35 作者:
對話框,大家對這個詞匯可謂是各有所解,本文有個不錯的例子,里面包含了各種常見對話框的實(shí)現(xiàn),感興趣的朋友可以了解下
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function confirmFun() {
//window 是文檔對象模型的最頂層對象,
//在調(diào)用它下面的自對象或方法時window可省:confirm("是否刪除?");
//這里會在頁面的最上方彈出一個可以選擇是或者否的對話框,其方法返回一個bool值,如果選擇了是返回true,選擇了否返回false
var b = window.confirm("是否刪除?");
if (b) {
alert("正在刪除中...");
} else {
alert("取消了刪除...");
}
}
//彈出對話框
function propmtFun() {
//這里提供了一個帶有輸入框的對話框,它的返回值是你輸入的內(nèi)容
//propmt(提示消息,默認(rèn)值)//輸入的內(nèi)容不是習(xí)近平時再次彈出,直到輸入對了為止
var re = window.prompt("國家主席是誰?", "死了");
while (re != "習(xí)近平") {
re = window.prompt("國家主席是誰?", "死了");
// propmtFun();
}
alert("歡迎進(jìn)入...");
}
//彈出頁面
function openFun() {
//這里可以彈出一個新的頁面,在這個方法的參數(shù)里可以設(shè)置頁面的高度等屬性
//window.open(要打開的頁面的路徑,頁面的名稱,頁面的屬性)
window.open("demo.htm", "", "top=0,left=0,width=300,height=200,location=no,toolbar=no,menubar=no,status=no");
}
//延時執(zhí)行
var vs = null;
function timeoutFun() {
var vf = function () { alert("hello"); };
//延時執(zhí)行的操作可以用一個變量記錄下來
//設(shè)置多少毫秒后執(zhí)行,參數(shù)是一個方法,和延遲的時間
vs = setTimeout(vf, 2000); //2000毫秒后執(zhí)行vf方法
}
//取消延時執(zhí)行
function cleartimeoutFun() {
//取消延遲執(zhí)行,方法的參數(shù)是一個setTimeout()方法
window.clearTimeout(vs);
}
//間隔執(zhí)行
var vi = null;
function intervalFun() {
var vf = function () {
var vt = new Date();
// alert(vt.toLocaleTimeString());
//在瀏覽器的狀態(tài)欄顯示當(dāng)前時間
window.status = vt.toLocaleTimeString();
var text = window.document.getElementById("msg").value = vt.toLocaleTimeString();
};
//設(shè)置vf方發(fā)每隔1000毫秒執(zhí)行一次
vi = window.setInterval(vf, 1000); //每個1000毫秒執(zhí)行一次vf方法
}
//停止間隔執(zhí)行
function clearintervalFun() {
window.clearInterval(vi);
}
//新消息提示
function msgFun() {
var str = "";
var vstr = "您有新短消息,請注意查收...";
window.document.title = str;
window.document.bgColor = "blue";
var i = 1;
setInterval(function () { window.document.title = vstr.substr(i, 50); i++; if (i == vstr.length) { i = 0; } }, 500)
}
</script>
</head>
<body>
<input type="button" value="是否對話框" onclick="confirmFun();" /><br />
<input type="button" value="輸入框" onclick="propmtFun();" /><br />
<input type="button" value="彈出頁面" onclick="openFun();" /><br />
<input type="text" id="msg" /><br />
<input type="button" value="延時執(zhí)行" onclick="timeoutFun();" /><br />
<input type="button" value="取消延時" onclick="cleartimeoutFun();" /><br />
<input type="button" value="間隔執(zhí)行" onclick="intervalFun();" /><br />
<input type="button" value="停止間隔執(zhí)行" onclick="clearintervalFun();" /><br />
<input type="button" value="新消息提示" onclick="msgFun();" /><br />
</body>
</html>
相關(guān)文章
javascript下過濾數(shù)組重復(fù)值的代碼
javascript下過濾數(shù)組重復(fù)值的代碼...2007-09-09
JS實(shí)現(xiàn)固定時間點(diǎn)執(zhí)行某任務(wù)的代碼示例
在Web前端開發(fā)中,有時我們需要在特定的時間點(diǎn)執(zhí)行某些任務(wù),例如每日定時發(fā)送數(shù)據(jù)報告、每小時更新一次用戶界面等,JavaScript 提供了多種方法來實(shí)現(xiàn)這一需求,本文將詳細(xì)介紹如何使用這些工具和技術(shù),并通過豐富的代碼示例展示其具體應(yīng)用,需要的朋友可以參考下2025-02-02
document.selection.createRange方法與實(shí)例
document.selection.createRange() 根據(jù)當(dāng)前文字選擇返回 TextRange 對象,或根據(jù)控件選擇返回 ControlRange 對象2006-10-10
node-http-proxy修改響應(yīng)結(jié)果實(shí)例代碼
這篇文章主要介紹了node-http-proxy修改響應(yīng)結(jié)果的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06
JavaScript實(shí)現(xiàn)快速排序的方法分析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)快速排序的方法,結(jié)合實(shí)例形式分析了快速排序的原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2018-01-01
JS頁面獲取 session 值,作用域和閉包學(xué)習(xí)筆記
這篇文章主要介紹了JS頁面獲取 session 值,作用域和閉包,結(jié)合具體實(shí)例形式分析了javascript與jsp交互獲取session值、函數(shù)作用域及閉包相關(guān)操作技巧,需要的朋友可以參考下2019-10-10
JavaScript進(jìn)階練習(xí)及簡單實(shí)例分析
下面小編就為大家?guī)硪黄狫avaScript進(jìn)階練習(xí)及簡單實(shí)例分析。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06

