- 热门文章:
- · 用javascript实现浮点数的截取小数位数,并四舍五入
- · three trim function(javascript)
- · 用ASP将javascript代码写入客户端执行的一种简易方法。。。
- · Trim Function in javascript
- · java分页源码
- · 过滤表格中的链接(用javascript提取表格中的数据)
- · 来看看哟.一个天气预报的小偷.可以偷到每天更新的全国24小时城市天气预报.
- · 一个把WORD转换成HTML的程序
- · 饮水思源,我从这里学到的知识投入应用,现在再奉献回给大家(可编辑页面的部分属性)
- · 用 WSH 想ASP 一样 查询数据库!(WSH 学习心得2)
- · 一段窗口自动关闭的源代码,不受js打开的限制,与大家共享!
- · 带进度条的关闭窗口,绝对有用!并可根据需要改写。
上一篇:Creating CSS Buttons (一) >>
Creating CSS Buttons (二)
Introduction
In an earlier article, Creating CSS Buttons, I examined how to create graphical-appearing buttons using nothing but HTML and CSS. While this approach is fairly simple to implement - just add a few style tags and a suitable HREF and DIV tag - it is a bit mundane to have to do for each and every button, especially since you need to have a unique set of style classes and IDs for each unique button. (If you are thoroughly confused by this point, be sure you@#ve read the Creating CSS Buttons article before delving into this one...) In this article we will examine a small, but handy class to help automate the process of creating CSS buttons. Furthermore, when using a class we@#ll be creating and placing buttons much like you would in a VB project. (For more information on creating and using classes in VBScript, be sure to read Mark Lidstone@#s excellent article: Using Classes within VBScript!)
Determining the Class Properties
The first step in creating our CSS button creating class is to decide what properties makeup a CSS button. While there is literally no limit to the number of properties one could conceivably attribute to a button, for this article I am going to assume that this set of properties conveys the basic features one would like to have in a button:
CssButton Class Properties
Name Uniquely identifies each button.
BackColor Specifies the background color of the button.
BorderColor Specifies the color of the button@#s border.
Font The font to use for the button@#s label. Must be in the format: style size font-name, such as: bold 12pt arial.
FontColor The color of the font when the button is not selected.
Width The width of the button.
Text The text to display on the button.
Url The Url to take the user to when the click the button.
MouseOverColor The color to make the font when the user@#s mouse moves over the button.
This will only work for visitors using IE...
These properties describe each button. Realize that you must use a unique Name for each independent button you want on a given Web page. If you create multiple buttons with the same name, when you mouse over one button, all of those buttons will highlight.
Creating the Class Methods
Now that we@#ve looked at the properties for the CssButton class, let@#s examine the two methods we@#ll need: GenerateStyleTag() and GenerateButtonTag(). Since each CSS button needs its own classes/IDs declared in a STYLE tag, and, additionally, needs an HREF/DIV section to display the button, these two methods return the applicable STYLE tag and HTML. These methods are very simple, and can be seen below:
Public Function GenerateStyleTag()
@#Create the STYLE tag
Dim strStyle
strStyle = "<STYLE TYPE=""text/css"">" & vbCrLf & _
"<!--" & vbCrLf & _
"#mybutton" & Name & " {border-style: inset; " & vbCrLf & _
" border-color: " & BorderColor & ";" & vbCrLf & _
" background-color: " & BackColor & ";" & vbCrLf & _
" width: " & Width & ";" & vbCrLf & _
" text-align: center; }" & vbCrLf & vbCrLf & vbCrLf & _
"A.buttontext" & Name & " {color: " & FontColor & "; " & vbCrLf & _
" text-decoration: none; " & vbCrLf & _
" font: " & Font & ";" & vbCrLf & _
" cursor: hand; }" & vbCrLf & vbCrLf & vbCrLf & _
".buttonover" & Name & " {color: " & MouseOverColor & ";" & vbCrLf & _
" text-decoration: none; " & vbCrLf & _
" font: " & Font & ";" & vbCrLf & _
" cursor: hand; }" & vbCrLf & _
" // -->" & vbCrLf & _
"</STYLE>"
GenerateStyleTag = strStyle
End Function
Public Function GenerateButtonTag()
Dim strHTML
strHTML = "<a href=""" & Url & """ class=""buttontext" & Name & """ " & _
"onMouseOver=""this.className=@#buttonover" & Name & "@#;"" " & _
"onMouseOut=""this.className=@#buttontext" & Name & "@#;"">" & _
vbCrLf & "<div id=""mybutton" & Name & """>" & vbCrLf & Text & _
vbCrLf & "</div></a>" & vbCrLf
GenerateButtonTag = strHTML
End Function
Creating a Button - the Whole Process
Now that we have outlined the properties in our class, along with the two needed methods, let@#s examine how we will actually create some buttons on a Web page. The first thing to do is to create an instance of our CssButton class for each CSS button that we wish to display on the page. (The complete source for the CssButton class is available in a download at the end of this article.)
A very simple example can be seen below. It creates two buttons, one that links to Yahoo! and one that links to Lycos. (Be sure to try out the live demo!)
@#... Insert declaration of CssButton class here ...
Dim btnYahoo, btnLycos
Set btnYahoo = New CssButton
Set btnLycos = New CssButton
btnYahoo.BackColor = "#aaaaaa"
btnYahoo.BorderColor = "#bbbbbb"
btnYahoo.Font = "bold 12pt Verdana"
btnYahoo.FontColor = "black"
btnYahoo.Width = "80px"
btnYahoo.MouseOverColor = "yellow"
btnYahoo.Url = "http://www.yahoo.com/"
btnYahoo.Name = "yahoo"
btnYahoo.Text = "Yahoo!"
@#Display the Yahoo button
Response.Write btnYahoo.GenerateStyleTag()
Response.Write btnYahoo.GenerateButtonTag()
Response.Write "<p> </p>"
btnLycos.BackColor = "#aaaaaa"
btnLycos.BorderColor = "#bbbbbb"
btnLycos.Font = "10pt Arial"
btnLycos.FontColor = "black"
btnLycos.Width = "70px"
btnLycos.MouseOverColor = "yellow"
btnLycos.Url = "http://www.lycos.com/"
btnLycos.Name = "lycos"
btnLycos.Text = "Lycos"
@#Display the Lycos button
Response.Write btnLycos.GenerateStyleTag()
Response.Write btnLycos.GenerateButtonTag()
[View a live demo!]
Pretty straightforward, no? To create a button, we simply create an instance of the CssButton class, set its properties, then call output the CSS/HTML of its GenerateStyleTag() and GenerateButtonTag() methods. Note that you should create all of your buttons and set all of the properties before you emit any HTML, and then display each button@#s associated style tags in the HEAD portion of the HTML document.
Hopefully with this class you@#ll find creating CSS buttons that much easier! Enjoy, and Happy Programming!
相关文章:
- · 一组javascript绘图函数
- · 限制只能中文输入的方法。(详细讲解,对象初学者)
- · 一般的页面滚动条是在右边的,想让他在左边吗:)
- · 确认是否关闭浏览器或转到其它页面(javascript)(做聊天室或在线人数的时候可以用上)
- · <body onkeypress=alert(event.keyCode)>请按任意键,你将得到该键的键值!(转)
- · 利用cookie收藏网站
- · 转贴一个扫雷游戏脚本
- · 动态按钮生成器(上)
- · 用Cookie实现仅弹出一次窗口(javascript)(转)
- · 动态按钮生成器(下)
- · 一全很经典的堆积演示程序(javascript)(转)
- · 一个很酷的程序javascript做的MID歌曲搜索播放器[IE](JS)_(转)
- · 一个查看ASP的javascript程序,方便大家学习ASP程序(JS)_转
- · 长串连续英文字符自动回行的方法(转)
- · 如何修复被修改的IE(1)
- · 如何修复被修改的IE(2)
- · 鼠标右键绝对禁止法
- · 改变浏览器的标题和加入收藏夹的js文件!
- · 零点的网页真黑!!
- · 超级Mailto功能
- · javascript的history对象
- · 又一个给浏览器的滚动条加上颜色的方法(转)
- · 动态计算还能够输入多少字节的表单(纯script,请吧昨天的精华替换成这个吧,那个中文也算1字节
- · 动态计算还能够输入多少字节的表单代码^O^(申请入精华)
- · Vbscript教程一
- · vbscript教程三
- · vbscript教程四-常量
- · vbscript教程五-使用条件语句
- · vbscript教程六-循环语句
- · VBScript教程七-过程
- · VBScript教程九-页面
- · VBScript教程八-编码
- · VBScript 与窗体(十)
- · VBScript 中使用对象(十一)
- · VBScript错误信息列表
- · javascript[对象.属性]集锦(建议加入精华区)
- · 介绍一个判断plug-ins/ActiveX 是否存在的例子
- · 不用询问关闭一个独立的窗口代码
