先為大家介紹javascript確認框的三種使用方法,具體內容如下
第一種方法:挺好用的,確認以后才能打開下載地址頁面。原理也比較清晰。主要用於刪除單條信息確認。
|
1
2
3
4
5
6
7
8
9
10
|
<SCRIPT LANGUAGE=javascript>
function
del() {
var
msg =
"您真的確定要刪除嗎?\n\n請確認!"
;
if
(confirm(msg)==
true
){
return
true
;
}
else
{
return
false
;
}
}
</SCRIPT>
|
調用方法:
|
1
|
<
a
href
=
"del.php?id=123"
onclick
=
"javascript:return del()"
>刪 除</
a
>
|
第二種方法:原理跟上面的一樣。JavaScript刪除確認框
|
1
|
<
a
href
=
"javascript:if(confirm('確實要刪除嗎?'))location='jb51.php?id='"
>刪除</
a
>
|
第三種方法:主要用於批量刪除的確認提示
|
1
2
3
4
5
6
7
8
9
10
11
|
<input name=
"Submit"
type=
"submit"
class=
"inputedit"
value=
"刪除"
onclick=
"{if(confirm('確定紀錄嗎?')){
this.document.formname.submit();
return true;}return false;
}"
>
<input name=
"按鈕"
type=
"button"
ID=
"ok"
onclick=
"{if(confirm('確定刪除嗎?')){
window.location='Action.asp?Action=Del&
TableName=Item&
ID=<%=ID%>';
return true;
}return false;}"
value=
"刪除欄目"
/>
|
再為大家分享一個實例:js的確認框confirm()代碼實例
效果圖:

confirm()確認框在網頁中比較常用,當然有些美觀度要求比較高的網頁可能需要自定義這樣的功能,下面就來介紹一下window對象的confirm()函數的用法,下面縣看一段代碼實例,因為沒有什么再比這個更直觀了。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<!DOCTYPE html>
<
html
>
<
head
>
<
meta
charset
=
"gb2312"
>
<
title
>confirm()代碼實例</
title
>
<
script
type
=
"text/javascript"
>
window.onload=function(){
var bt=document.getElementById("bt");
bt.onclick=function(){
if(confirm("真的要刪除嗎?")){
alert("點擊了確認按鈕");
}
else{
alert("點擊了取消按鈕");
}
}
}
</
script
>
</
head
>
<
body
>
<
input
type
=
"button"
id
=
"bt"
value
=
"點擊彈出確認框"
/>
</
body
>
</
html
>
|
以上代碼是一個confirm的簡單實例,可以很清晰的演示confirm()的作用,下面做一些總結:
1.confirm()函數中的參數是確認框的提示語。
2.此函數返回值是布爾型的,點擊確定,返回值為true,點擊取消返回值為false。
以上就是關於js確認框confirm()用法的實例,內容很豐富,希望大家喜歡。
