网站首页
网站导航
Ctrl+D收藏
首 页
代码段
源码包
文档库
工具箱
代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
JS
】
为按钮添加图标
作者:
dezai
/ 发布于
2014/4/8
/
384
<HTML> <HEAD> <TITLE>动态的按钮</TITLE> <STYLE type=text/css> .STYLE1 { font-family: "华文行楷"; font-weight: bold; font-size: 13pt; } .STYLE3 { color: #9900CC; font-weight: bold; } .STYLE4 { color: #CC0000; font-weight: bold; } </STYLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> </HEAD> <BODY bgColor=#fef4d9> <CENTER><FONT face=隶书 color=red size=6>动态的按钮</FONT></CENTER><BR> <CENTER> <TABLE borderColor=#CCFFFF border=5 borderlight="green"> <TBODY> <TR> <TD align=middle> <SCRIPT> document.onmouseover = doOver; document.onmouseout = doOut; document.onmousedown = doDown; document.onmouseup = doUp; function doOver() { var toEl = getReal(window.event.toElement, "className", "coolButton"); var fromEl = getReal(window.event.fromElement, "className", "coolButton"); if (toEl == fromEl) return; var el = toEl; var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present if (el.className == "coolButton") el.onselectstart = new Function("return false"); if ((el.className == "coolButton") && !cDisabled) { makeRaised(el); makeGray(el,false); } } function doOut() { var toEl = getReal(window.event.toElement, "className", "coolButton"); var fromEl = getReal(window.event.fromElement, "className", "coolButton"); if (toEl == fromEl) return; var el = fromEl; var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present var cToggle = el.cToggle; toggle_disabled = (cToggle != null); // If CTOGGLE atribute is present if (cToggle && el.value) { makePressed(el); makeGray(el,true); } else if ((el.className == "coolButton") && !cDisabled) { makeFlat(el); makeGray(el,true); } } function doDown() { el = getReal(window.event.srcElement, "className", "coolButton"); var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present if ((el.className == "coolButton") && !cDisabled) { makePressed(el) } } function doUp() { el = getReal(window.event.srcElement, "className", "coolButton"); var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present if ((el.className == "coolButton") && !cDisabled) { makeRaised(el); } } function getReal(el, type, value) { temp = el; while ((temp != null) && (temp.tagName != "BODY")) { if (eval("temp." + type) == value) { el = temp; return el; } temp = temp.parentElement; } return el; } function findChildren(el, type, value) { var children = el.children; var tmp = new Array(); var j=0; for (var i=0; i<children.length; i++) { if (eval("children[i]." + type + "==\"" + value + "\"")) { tmp[tmp.length] = children[i]; } tmp = tmp.concat(findChildren(children[i], type, value)); } return tmp; } function disable(el) { if (document.readyState != "complete") { window.setTimeout("disable(" + el.id + ")", 100); return; } var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); if (!cDisabled) { el.cDisabled = true; el.innerHTML = '<span style="background: buttonshadow; width: 100%; height: 100%; text-align: center;">' + '<span style="filter:Mask(Color=buttonface) DropShadow(Color=buttonhighlight, OffX=1, OffY=1, Positive=0); height: 100%; width: 100%%; text-align: center;">' + el.innerHTML + '</span>' + '</span>'; if (el.onclick != null) { el.cDisabled_onclick = el.onclick; el.onclick = null; } } } function enable(el) { var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present if (cDisabled) { el.cDisabled = null; el.innerHTML = el.children[0].children[0].innerHTML; if (el.cDisabled_onclick != null) { el.onclick = el.cDisabled_onclick; el.cDisabled_onclick = null; } } } function addToggle(el) { var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present var cToggle = el.cToggle; cToggle = (cToggle != null); // If CTOGGLE atribute is present if (!cToggle && !cDisabled) { el.cToggle = true; if (el.value == null) el.value = 0; // Start as not pressed down if (el.onclick != null) el.cToggle_onclick = el.onclick; // Backup the onclick else el.cToggle_onclick = ""; el.onclick = new Function("toggle(" + el.id +"); " + el.id + ".cToggle_onclick();"); } } function removeToggle(el) { var cDisabled = el.cDisabled; cDisabled = (cDisabled != null); // If CDISABLED atribute is present var cToggle = el.cToggle; cToggle = (cToggle != null); // If CTOGGLE atribute is present if (cToggle && !cDisabled) { el.cToggle = null; if (el.value) { toggle(el); } makeFlat(el); if (el.cToggle_onclick != null) { el.onclick = el.cToggle_onclick; el.cToggle_onclick = null; } } } function toggle(el) { el.value = !el.value; if (el.value) el.style.background = "URL(home.gif)"; else el.style.backgroundImage = ""; // doOut(el); } function makeFlat(el) { with (el.style) { background = ""; border = "1px solid buttonface"; padding = "1px"; } } function makeRaised(el) { with (el.style) { borderLeft = "1px solid buttonhighlight"; borderRight = "1px solid buttonshadow"; borderTop = "1px solid buttonhighlight"; borderBottom = "1px solid buttonshadow"; padding = "1px"; } } function makePressed(el) { with (el.style) { borderLeft = "1px solid buttonshadow"; borderRight = "1px solid buttonhighlight"; borderTop = "1px solid buttonshadow"; borderBottom = "1px solid buttonhighlight"; paddingTop = "2px"; paddingLeft = "2px"; paddingBottom = "0px"; paddingRight = "0px"; } } function makeGray(el,b) { var filtval; if (b) filtval = "gray()"; else filtval = ""; var imgs = findChildren(el, "tagName", "IMG"); for (var i=0; i<imgs.length; i++) { imgs[i].style.filter = filtval; } } document.write("<style>"); document.write(".coolBar {background: buttonface;border-top: 1px solid buttonhighlight; border-left: 1px solid buttonhighlight; border-bottom: 1px solid buttonshadow; border-right: 1px solid buttonshadow; padding: 2px; font: menu;}"); document.write(".coolButton {border: 1px solid buttonface; padding: 1px; text-align: center; cursor: default;}"); document.write(".coolButton IMG{filter: gray();}"); document.write("</style>"); </SCRIPT> <TABLE class=coolBar> <TBODY> <TR> <TD class=coolButton><div align="center" class="STYLE3"><FONT onclick="window.location='http://www.baidu.com'" face=Verdana size=3>百度一下</FONT> </div></TD> <TD class=coolButton><div align="center" class="STYLE4"><FONT onclick="window.location='http://www.sina.com.cn'" face=Verdana size=2>新浪网</FONT> </div></TD></TR></TBODY></TABLE> <DIV class=coolBar style="WIDTH: 100px"><SPAN class=coolButton style="WIDTH: 100px" onclick="window.location='http://www.sohu.com'"><IMG src="/jscss/demoimg/201303/home.gif"> <span class="STYLE1">欢迎进入</span></SPAN></DIV></TD></TR></TBODY></TABLE> </CENTER> </BODY> </HTML>
评论列表
本站所提供的代码,版权归原作者所有,若有侵犯作者版权,请与我们联系,我们将立即删除或修改。谢谢!
本站所有代码发布及提供者。
试试其它关键字
按钮添加图标
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
判断用户输入的是否为IP地址
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
地图
本站
我们
服务
版权
联系
回馈
博客