2.进阶篇
1. object插件的工作原理
object插件的作用流程如下:
| 1 | dreamweaver检测object插件代码里是否存在form标签, 如果form存在,首先调用windowdimensions()函数,计算参数选择对话框的尺寸,如果windowdimensions()没有定义,dreamweaver自动定义对话框的尺寸,最后弹出参数对话框, 如果form不存在,就不弹出对话框,直接跳到第三步 |
| 2 | 用户在对话框中选择参数,然后点击ok按钮 |
| 3 | dreamweaver调用objecttag()函数,将其返回的值插入到当前位置 |
|
该表格框架的宽度、背景颜色、活动颜色都是用户自己定制的。知道效果了,我们开始动吧!
ex2.1 首先设计我们插件的实际html代码。
本例的代码如下:
〈table width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="#000066" onmouseover="this.style.backgroundcolor=\'#ff0000\'" onmouseout="this.style.backgroundcolor=\'#000066\'"〉
〈tr〉
〈td〉 〈/td〉
〈/tr〉
〈tr〉
〈td〉
〈table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"〉
〈tr〉
〈td〉 〈/td〉
〈/tr〉
〈/table〉
〈/td〉
〈/tr〉
〈/table〉
ex2.2 确定用户的输入参数。
参数1:大表格的宽度,width=?
参数2:大表格的背景颜色bgcolor=?
参数3:大表格的动态颜色this.style.backgroundcolor=?
ex2.3 设计实践:
将ex1.2.1的源代码转化为一个js文件,它包含一个函数objecttag()即可,同时需要一个.htm文件,用于传递参数。
本例的具体代码为:
1: dhtmltabletitle.js的源文件如下:
function objecttag(){
//表格宽度参数
var ttwidth=document.theform.width.value;
//宽度单位
var unitchoice = document.forms[0].units.selectedindex;
var ttunit=((unitchoice == 0)? \'%\' : \'\');
//表格背景颜色
var ttbgcolor=document.theform.bgcolor.value;
//表格动态背景颜色
var ttdbgcolor=document.theform.dbgcolor.value;
//插入的具体代码
var tabletitle="";
tabletitle+="〈table width=\\"" + ttwidth + ttunit +"\\" border=\\"0\\" cellspacing=\\"0\\" cellpadding=\\"1\\" bgcolor=\\\'" + ttbgcolor +"\\\' onmouseover=\\"this.style.backgroundcolor=\\\'" + ttdbgcolor + "\\\'\\" onmouseout=\\"this.style.backgroundcolor=\\\'" + ttbgcolor + "\\\'\\"〉";
tabletitle+=" 〈tr〉";
tabletitle+=" 〈td〉 〈/td〉";
tabletitle+=" 〈/tr〉";
tabletitle+=" 〈tr〉";
tabletitle+=" 〈td〉";
tabletitle+=" 〈table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#ffffff〉";
tabletitle+=" 〈tr〉";
tabletitle+=" 〈td〉 〈/td〉";
tabletitle+=" 〈/tr〉";
tabletitle+=" 〈/table〉";
tabletitle+=" 〈/td〉";
tabletitle+=" 〈/tr〉";
tabletitle+="〈/table〉";
return tabletitle;
}
2:dhtmltabletitle.htm 的源代码如下:
〈html〉
〈head〉
〈title〉tabletitle〈/title〉
〈meta http-equiv="content-type" content="text/html; charset=gb2312"〉
〈script src="tabletitle.js"〉〈/script〉
〈/head〉
〈body〉
〈form name="theform" method="post" action=""〉
〈table width="250" border="0" cellspacing="0" cellpadding="0"〉
〈tr〉
〈td width="81"〉表格宽度:〈/td〉
〈td width="169"〉
〈input type="text" name="width" size="5" maxlength="5"〉
〈select name="units" size="1"〉
〈option selected〉%〈/option〉
〈option〉像素〈/option〉
〈/select〉
〈/td〉
〈/tr〉
〈tr〉
〈td width="81"〉表格背景:〈/td〉
〈td width="169"〉〈input type="text" name="bgcolor" size="8" maxlength="8"〉〈input type="mmcolorbutton" name="colorbutton1" onchange="this.form.bgcolor.value=this.form.colorbutton1.value"〉
〈/td〉
〈/tr〉
〈tr〉
〈td width="81"〉动态背景:〈/td〉
〈td width="169"〉〈input type="text" name="dbgcolor" size="8" maxlength="8"〉
〈input type="mmcolorbutton" name="colorbutton" onchange="this.form.dbgcolor.value=this.form.colorbutton.value"〉
〈/td〉
〈/tr〉
〈tr align="right"〉
〈td colspan="2"〉〈hr noshade width="100%" size="2"〉〈font face="verdana, arial, helvetica, sans-serif" size="2"〉2001.1.15〈br〉
design by redidea〈br〉
email:redidea@hotmail.com〈/font〉〈/td〉
〈/tr〉
〈/table〉
〈/form〉
〈/body〉
〈/html〉
说明:本例用到两个颜色选取器,它实际上是一个macromeida的特殊〈input〉,代码是〈input type="mmcolorbutton" name="colorbutton" onchange="this.form.dbgcolor.value=this.form.colorbutton.value"〉,其中的onchange事件触发选取的颜色值,然后传递到颜色值的输入框,这样就能方便用户取的颜色值。
安装:将dhtmltabletitle.js和dhtmltabletitle.htm两个文件拷贝到dreamweaver安装目录下的/configuration/objects/redidea目录下,重新装入插件(参照1.1.2插件的安装),你会发现一个新的插件出现在redidea类里,如果你需要自己的图标,请参照2.1.3.3 gif文件的规定,哈哈,成功了!
3.object插件的编写总结
object插件一般需要三个文件:.htm文件,.js文件和.gif文件
3.1 htm文件的设计要点:
该文件的〈title〉和〈/title〉中的字符就是该插件的名称,同时要通过〈script〉指明js文件的位置,这样才能完成参数的成功传递。
3.2 js文件的设计要点:
该文件必须包含一个objecttag()函数,必须有返回值,并且他的就是将来使用者的html源代码。
3.3 gif文件的规定: 该文件名必须与htm文件名相同,大小必须是18px*18px(注:px表示像素单位),如果没有gif文件,dreamweaver将给出一个默认的?图标,为了美观和方便,一般都要设计一个形象的图标。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器