zoukankan
html css js c++ java
利用Javascript的“函数重载”实现自定义Alert样式
默认的Alert只有一个简单的对话框,而且无法自定义样式!有时候弹出的提示需要很详尽,并且显得有些冗长,那么如何让用户直接看到重点信息呢?因为系统自带的Alert无法编辑样式所以我们只好自己重新定义一个了!
先看看我经常使用的信息提示样式吧!
数据传递错误
[软件编号]:
必须是0-9的阿拉伯数字!
这其实就是一个普通的Html表格,里面加上2个操作按钮!
完整的HTML代码如下:
<
table
width
="300"
border
="0"
align
="center"
cellpadding
="0"
cellspacing
="1"
bgcolor
="#CCCCCC"
>
<
tr
>
<
td
align
="center"
bgcolor
="#CCCCCC"
><
span
class
="STYLE1"
>
操作提示
</
span
></
td
>
</
tr
>
<
tr
>
<
td
bgcolor
="#FFFFFF"
>
</
td
>
</
tr
>
<
tr
>
<
td
align
="center"
bgcolor
="#FFFFFF"
><
input
type
="button"
name
="Submit"
value
="返回"
onclick
="window.history.go(-1)"
/>
<
input
type
="button"
name
="Submit2"
value
="关闭"
onclick
="window.close()"
/></
td
>
</
tr
>
</
table
>
你可以把这些代码改成任何你喜欢的样式,但是最好留下返回和关闭按钮。PS:没有操作按钮就没法返回上一页拉!
接下来把这些表格代码转换成JS,并且利用JS的“函数重载”重新定义系统自带的Alert 窗口。
具体代码如下:
<
Script Language
=
"
JavaScript
"
>
window.alert
=
function
(txt)
...
{
document.write (
'
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
'
);
document.write (
'
<tr>
'
);
document.write (
'
<td align="center" bgcolor="#CCCCCC"><span class="STYLE1">操作提示</span></td>
'
);
document.write (
'
</tr>
'
);
document.write (
'
<tr>
'
);
document.write (
'
<td bgcolor="#FFFFFF">
'
+
txt
+
'
</td>
'
);
document.write (
'
</tr>
'
);
document.write (
'
<tr>
'
);
document.write (
'
<td align="center" bgcolor="#FFFFFF"><input type="button" name="Submit" value="返回" onclick="window.history.go(-1)"/>
'
);
document.write (
'
<input type="button" name="Submit2" value="关闭" onclick="window.close()"/></td>
'
);
document.write (
'
</tr>
'
);
document.write (
'
</table>
'
);
}
</
Script
>
一切就绪,现在我们只需要按原来的方法调用Alert就好了
查看全文
相关阅读:
【6666】分组背包
Designing a RESTful API with Python and Flask 201
把手账打印成书 把回忆装订成册
sql基本操作语句
sql serve基础
sql serve存储过程
TCP/IP 之 大明王朝邮差 (转)
HBASE基础(4):语法(2) API (1) DDL
bochsrc
CentOS 6 bochs-2.6 gdb 调试 linux 0.11——bochsrc-hdc-gdb.bxrc
原文地址:https://www.cnblogs.com/zhangpengshou/p/937233.html
最新文章
电商门店装修大全
SQL Server 2005 发布 订阅 (配置实例[图])(转载)
SQL2005删除复制数据库的发布与订阅的方法(转载)
【9005】最短网络agrinet
【9003】繁忙的都市
【9002】局域网
【9004】&&【7010】最优布线问题
【9922】科技庄园
【9921】暗黑破坏神
并查集
热门文章
大概是:整数划分||DP||母函数||递推
HDU1068 二分匹配 独立集
3:拦截导弹(最长上升子序列)
软能力那点事,你知多少
【9906】装箱问题
[慕课笔记] node+mongodb建站攻略
【9911】质数和分解
【9910】竞赛总分
【9905】砝码称重
【9909】货币系统
Copyright © 2011-2022 走看看