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就好了
查看全文
相关阅读:
雷锋依然在人间 工厂方法模式
为别人做嫁衣 代理模式
穿什么有这么重要? 装饰模式
437. Path Sum III
434. Number of Segments in a String
447. Add Strings
414. Third Maximum Number
412. Fizz Buzz
404. Sum of Left Leaves
405. Convert a Number to Hexadecimal
原文地址:https://www.cnblogs.com/zhangpengshou/p/937233.html
最新文章
协同过滤推荐算法
拉格朗日乘子法和KKT条件
hadoop下的Kmeans算法实现
javax.el.PropertyNotFoundException: Property 'depservice' not found on type com.baway.pojo.Employee
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in class path resource [applicationContext.xml]: Ca
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.baway.dao.UserMapper.register
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.facto
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method
org.springframework.orm.hibernate3.HibernateQueryException: CupType is not mapped [from CupType]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: CupType is not mapped [from CupType]
message not-null property references a null or transient value: com.bawei.test.entity.Game.name; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transi
热门文章
hibernate中inverse属性详解
hibernate中 cascade属性详解
hibernate关联四个方向
就不能换DB吗? 抽象工厂模式
老板回来我不知道 观察者模式
好菜没盐味不同 建造者模式
牛市股票还会亏钱? 外观模式
无熟人难办事? 迪米特法则
考题抄错会做也白搭 模板方法模式
简历复印 原型模式
Copyright © 2011-2022 走看看