选择显示字体大小

教程/dreamweaver/高级 深入dreamweaver插件的奥秘(4)

2.进阶篇

  1. object插件的工作原理
  object插件的作用流程如下:

1dreamweaver检测object插件代码里是否存在form标签,
如果form存在,首先调用windowdimensions()函数,计算参数选择对话框的尺寸,如果windowdimensions()没有定义,dreamweaver自动定义对话框的尺寸,最后弹出参数对话框,
如果form不存在,就不弹出对话框,直接跳到第三步
2用户在对话框中选择参数,然后点击ok按钮
3dreamweaver调用objecttag()函数,将其返回的值插入到当前位置

  2. object插件实战
  上节所讲的是最简单的object插件,有时候觉得不够用,比如需要动态效果,或者需要用户输入自己的参数的时候,就必须进一步改造我们的插件.

  example 2:本文将讲述的插件是一个用户可以定制的高级表格框架,效果如下
 

样例example 2



  该表格框架的宽度、背景颜色、活动颜色都是用户自己定制的。知道效果了,我们开始动吧!
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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons