这是编码问题,在utf-8页面下无问题, 只要在载入google时加入&oe=gb2312 就可以了
2012-1-30 17:49 Monday  

利用Javascript取和设FCKeditor值也是非常容易的,如下:

// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    return(oEditor.GetXHTML(true));
}

// 获取编辑器中文字内容
function getEditorTextContents(EditorName) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    return(oEditor.EditorDocument.body.innerText);
}

// 设置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName) ;
    oEditor.SetHTML(ContentStr) ;
}

FCKeditorAPI是FCKeditor加载后注册的一个全局对象,利用它我们就可以完成对编辑器的各种操作。

在当前页获得 FCK 编辑器实例:
var Editor = FCKeditorAPI.GetInstance('InstanceName');

从 FCK 编辑器的弹出窗口中获得 FCK 编辑器实例:
var Editor = window.parent.InnerDialogLoaded().FCK;

从框架页面的子框架中获得其它子框架的 FCK 编辑器实例:
var Editor = window.FrameName.FCKeditorAPI.GetInstance('InstanceName');

从页面弹出窗口中获得父窗口的 FCK 编辑器实例:
var Editor = opener.FCKeditorAPI.GetInstance('InstanceName');

获得 FCK 编辑器的内容:
oEditor.GetXHTML(formatted); // formatted 为:true|false,表示是否按HTML格式取出
也可用:
oEditor.GetXHTML();

设置 FCK 编辑器的内容:
oEditor.SetHTML("content", false); // 第二个参数为:true|false,是否以所见即所得方式设置其内容。此方法常用于"设置初始值"或"表单重置"哦作。

插入内容到 FCK 编辑器:
oEditor.InsertHtml("html"); // "html"为HTML文本

检查 FCK 编辑器内容是否发生变化:
oEditor.IsDirty();

在 FCK 编辑器之外调用 FCK 编辑器工具条命令:
命令列表如下:
DocProps, Templates, Link, Unlink, Anchor, BulletedList, NumberedList, About, Find, Replace, Image, Flash, SpecialChar, Smiley, Table, TableProp, TableCellProp, UniversalKey, Style, FontName, FontSize, FontFormat, Source, Preview, Save, NewPage, PageBreak, TextColor, BGColor, PasteText, PasteWord, TableInsertRow, TableDeleteRows, TableInsertColumn, TableDeleteColumns, TableInsertCell, TableDeleteCells, TableMergeCells, TableSplitCell, TableDelete, Form, Checkbox, Radio, TextField, Textarea, HiddenField, Button, Select, ImageButton, SpellCheck, FitWindow, Undo, Redo

使用方法如下:
oEditor.Commands.GetCommand('FitWindow').Execute();

= FCKConfig.BasePath + 'plugins/'  
// FCKConfig.Plugins.Add( 'placeholder', 'en,it' ) ;


去掉//后,就相当于把placeholder这个插件功能加上了,fckeditor的插件文件都在/editor/plugins/文件夹下分类按文 件夹放置的,对于fckeditor2.0来说,里面有两个文件夹,也就是有两个官方插件,placeholder这个文件夹就是我们刚才加上去的,主要 用于多参数或单参数自定义标签的匹配,这个在制作编辑模板时非常管用,要想看具体实例的话,大家可以去下载acms 这个系统查看学习,另一个文件夹tablecommands就是编辑器里的表格编辑用到的了。当然,如果你想制作自己其它用途的插件,那就只要按照 fckeidtor插件的制作规则制作完放置在/editor/plugins/下就行,然后再在fckeidtor.js里再添加 FCKConfig.Plugins.Add('Plugin Name',',lang,lang');就可以了。

第二部分 ,如何让编辑器一打开的时候,编辑工具条不出现,等点“展开工具栏”时才出现?Easy,FCKeditor本身提供了这个功能啦,打开fckconfig.js,找到

FCKConfig.ToolbarStartExpanded = true ;
改成
FCKConfig.ToolbarStartExpanded = false ;
就可以啦!

第三部分,使用自己的表情图标,同样打开fckcofnig.js到最底部那一段


FCKConfig.SmileyPath = FCKConfig.BasePath + 'images/smiley/msn/' ;
FCKConfig.SmileyImages = ['regular_smile.gif','sad_smile.gif','wink_smile.gif'] ;
FCKConfig.SmileyColumns = 8 ;
FCKConfig.SmileyWindowWidth    = 320 ;
FCKConfig.SmileyWindowHeight = 240 ;

上面这段已经是我修改过的了,为了我发表此文的版面不会被撑得太开,我把FCKConfig.SmileyImages那一行改得只有三个表情图了。

第一行,当然是表情图标路径的设置,第二行是相关表情图标文件名的一个List,第三行是指弹出的表情添加窗口最每行的表情数,下面两个参数是弹出的模态窗口的宽和高喽。

第四部分,文件上传管理部分

此部分可能是大家最为关心的,上一篇文章简单的讲了如何修改来上传文件以及使用fckeidtor2.0才提供的快速上传功能。再我们继续再深层次的讲解上传功能

FCKConfig.LinkBrowser = true ;
FCKConfig.ImageBrowser = true ;
FCKConfig.FlashBrowser = true ;在fckconfig.js找到这三句,这三句不是连着的哦,只是我把他们集中到这儿来了,设置为true的意思就是允许使用fckeditor来浏览 服务器端的文件图像以及flash等,这个功能是你插入图片时弹出的窗口上那个“浏览服务器”按钮可以体现出来,如果你的编辑器只用来自己用或是只在后台 管理用,这个功能无疑很好用,因为他让你很直观地对服务器的文件进行上传操作。但是如果你的系统要面向前台用户或是像blog这样的系统要用的话,这个安 全隐患可就大了哦。于是我们把其一律设置为false;如下

FCKConfig.LinkBrowser = false ;
FCKConfig.ImageBrowser = false ;
FCKConfig.FlashBrowser = false ;

Aboc的话:我自己是弄PHP的,文件上传部分(PHP)有修改成自己需要的,且有加上水印功能,至于下下面这部分,对我来说是没什么用的,不删除是为了保留转载此文的完整性


这样一来,我们就只有快速上传可用了啊,好!接下来就来修改,同样以asp为范例进行,进入/editor/filemanager/upload/asp/打开config.asp,修改
ConfigUserFilesPath = "/UserFiles/"这个设置是上传文件的总目录,我这里就不动了,你想改自己改了

好,再打开此目录下的upload.asp文件,找到下面这一段


Dim resourceType
If ( Request.QueryString("Type") <> "" ) Then
resourceType = Request.QueryString("Type")
Else
resourceType = "File"
End If
然后再在其后面添加


ConfigUserFilesPath = ConfigUserFilesPath & resourceType &"/"& Year(Date()) &"/"& Month(Date()) &"/"
这样的话,上传的文件就进入“/userfiles/文件类型(如image或file或flash)/年/月/”这样的文件夹下了,这个设置对单用户来用已经足够了,如果你想给多用户系统用,那就这样来改


ConfigUserFilesPath = ConfigUserFilesPath & Session("username") & resourceType &"/"& Year(Date()) &"/"& Month(Date()) &"/"
这样上传的文件就进入“/userfiles/用户目录/文件类型/年/月/”下了,当然如果你不想这么安排也可以修改成别的,比如说用户目录再深一层等,这里的Session("username")请根据自己的需要进行修改或换掉。

上传的目录设置完了,但是上传程序还不会自己创建这些文件夹,如果不存在的话,上传不会成功的,那么我们就得根据上面的上传路径的要求进行递归来生成目录了。

找到这一段


Dim sServerDir
sServerDir = Server.MapPath( ConfigUserFilesPath )
If ( Right( sServerDir, 1 ) <> "\" ) Then
    sServerDir = sServerDir & "\"
End If

把它下面的这两行


Dim oFSO
Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
用下面这一段代码来替换


dim arrPath,strTmpPath,intRow
strTmpPath = ""
arrPath = Split(sServerDir, "\")
Dim oFSO
Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
for intRow = 0 to Ubound(arrPath)
    strTmpPath = strTmpPath & arrPath(intRow) & "\"
    if oFSO.folderExists(strTmpPath)=false then
     oFSO.CreateFolder(strTmpPath)
    end if
next
用这段代码就可以生成你想要的文件夹了,在上传的时候自动生成。

好了,上传文件的修改到现在可以暂时告一段落了,但是,对于中文用户还存在这么个问题,就是fckeditor的文件上传默认是不改名的,同时还不支持中 文文件名,这样一来是上传的文件会变成“.jpg”这样的无法读的文件,再就是会有重名文件,当然重名这点倒没什么,因为fckeditor会自动改名, 会在文件名后加(1)这样来进行标识。但是,我们通常的习惯是让程序自动生成不重复的文件名

在刚才那一段代码的下面紧接着就是
' Get the uploaded file name.
sFileName = oUploader.File( "NewFile" ).Name
看清楚了,这个就是文件名啦,我们来把它改掉,当然得有个生成文件名的函数才行,改成下面这样

'//取得一个不重复的序号
Public Function GetNewID()
dim ranNum
dim dtNow
randomize
dtNow=Now()
ranNum=int(90000*rnd)+10000
GetNewID=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum
End Function

' Get the uploaded file name.
sFileName = GetNewID() &"."& split(oUploader.File( "NewFile" ).Name,".")(1)

这样一来,上传的文件就自动改名生成如20050802122536365.jpg这样的文件名了,是由年月日时分秒以及三位随机数组成的文件名了

2012-1-30 17:41 Monday  

不能像php那样的语言一样定义,只能采用

function showAlert(str,alertw,alerth){

   var alertw=arguments[1]?arguments[1]:400;
   var alerth=arguments[2]?arguments[2]:100;

}

这样的方式定义..

借肋于arguments 是实参数组

2012-1-30 17:26 Monday  
<SCRIPT language=JavaScript>
<!--

/**//*
*     消息构造
*/
function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action){
     this.id      = id;
     this.title   = title;
     this.caption= caption;
     this.message= message;
     this.target = target;
     this.action = action;
     this.width     = width?width:200;
     this.height = height?height:120;
     this.timeout= 150;
     this.speed     = 20;
     this.step     = 1;
     this.right     = screen.width -1;
     this.bottom = screen.height;
     this.left     = this.right - this.width;
     this.top     = this.bottom - this.height;
     this.timer     = 0;
     this.pause     = false;
     this.close     = false;
     this.autoHide     = true;
}

/**//*
*     隐藏消息方法
*/
CLASS_MSN_MESSAGE.prototype.hide = function(){
     if(this.onunload()){

         var offset   = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
         var me   = this;

         if(this.timer>0){  
             window.clearInterval(me.timer);
         }

         var fun = function(){
             if(me.pause==false||me.close){
                 var x   = me.left;
                 var y   = 0;
                 var width = me.width;
                 var height = 0;
                 if(me.offset>0){
                     height = me.offset;
                 }
    
                 y   = me.bottom - height;
    
                 if(y>=me.bottom){
                     window.clearInterval(me.timer);
                     me.Pop.hide();
                 } else {
                     me.offset = me.offset - me.step;
                 }
                 me.Pop.show(x,y,width,height);   
             }            
         }

         this.timer = window.setInterval(fun,this.speed)     
     }
}

/**//*
*     消息卸载事件,可以重写
*/
CLASS_MSN_MESSAGE.prototype.onunload = function() {
     return true;
}
/**//*
*     消息命令事件,要实现自己的连接,请重写它
*
*/
CLASS_MSN_MESSAGE.prototype.oncommand = function(){
     //this.close = true;
     this.hide();
window.open('http://dagongz.com');
  
}
/**//*
*     消息显示方法
*/
CLASS_MSN_MESSAGE.prototype.show = function(){

     var oPopup = window.createPopup(); //IE5.5+
   
     this.Pop = oPopup;

     var w = this.width;
     var h = this.height;

     var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>"
         str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"
         str += "<TR>"
         str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>"
         str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>"
         str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>"
         str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"
         str += "</TR>"
         str += "<TR>"
         str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">"
         str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 8px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 8px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>" + this.title + "<BR><BR>"
         str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=false id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A> - <A href='http://dagongz.com' hidefocus=false id='ommand'><FONT color=#ff0000>收件箱</FONT></A></DIV>"
         str += "</DIV>"
         str += "</TD>"
         str += "</TR>"
         str += "</TABLE>"
         str += "</DIV>"

     oPopup.document.body.innerHTML = str;
   

     this.offset   = 0;
     var me   = this;

     oPopup.document.body.onmouseover = function(){me.pause=true;}
     oPopup.document.body.onmouseout = function(){me.pause=false;}

     var fun = function(){
         var x   = me.left;
         var y   = 0;
         var width     = me.width;
         var height     = me.height;

             if(me.offset>me.height){
                 height = me.height;
             } else {
                 height = me.offset;
             }

         y   = me.bottom - me.offset;
         if(y<=me.top){
             me.timeout--;
             if(me.timeout==0){
                 window.clearInterval(me.timer);
                 if(me.autoHide){
                     me.hide();
                 }
             }
         } else {
             me.offset = me.offset + me.step;
         }
         me.Pop.show(x,y,width,height);   

     }

     this.timer = window.setInterval(fun,this.speed)     

    

     var btClose = oPopup.document.getElementById("btSysClose");

     btClose.onclick = function(){
         me.close = true;
         me.hide();
     }

     var btCommand = oPopup.document.getElementById("btCommand");
     btCommand.onclick = function(){
         me.oncommand();
     }   
   var ommand = oPopup.document.getElementById("ommand");
       ommand.onclick = function(){
        //this.close = true;
     me.hide();
window.open(ommand.href);
     }  
}
/**//*
** 设置速度方法
**/
CLASS_MSN_MESSAGE.prototype.speed = function(s){
     var t = 20;
     try {
         t = praseInt(s);
     } catch(e){}
     this.speed = t;
}
/**//*
** 设置步长方法
**/
CLASS_MSN_MESSAGE.prototype.step = function(s){
     var t = 1;
     try {
         t = praseInt(s);
     } catch(e){}
     this.step = t;
}

CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){
     try {
         this.left         = left     !=null?left:this.right-this.width;
         this.right         = right     !=null?right:this.left +this.width;
         this.bottom         = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
         this.top         = top     !=null?top:this.bottom - this.height;
     } catch(e){}
}
var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","懒人图库");
     MSG1.rect(null,null,null,screen.height-50);
     MSG1.speed     = 10;
     MSG1.step     = 5;
     //alert(MSG1.top);
     MSG1.show();

//同时两个有闪烁,只能用层代替了,不过层不跨框架
//var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");
//    MSG2.rect(100,null,null,screen.height);
//     MSG2.show();
//-->
</SCRIPT>

2012-1-30 17:19 Monday  

1.Date
属性(1):
constructor      所建立对象的函数参考
prototype       能够为对象加入的属性和方法

方法(43):
getDay()        返回一周中的第几天(0-6)
getYear()       返回年份.2000年以前为2位,2000(包含)以后为4位
getFullYear()     返回完整的4位年份数
getMonth()      返回月份数(0-11)
getDate()       返回日(1-31)
getHours()       返回小时数(0-23)
getMinutes()      返回分钟(0-59)
getSeconds()      返回秒数(0-59)
getMilliseconds() 返回毫秒(0-999)
getUTCDay()      依据国际时间来得到现在是星期几(0-6)
getUTCFullYear()    依据国际时间来得到完整的年份
getUTCMonth()     依据国际时间来得到月份(0-11)
getUTCDate()      依据国际时间来得到日(1-31)
getUTCHours()     依据国际时间来得到小时(0-23)
getUTCMinutes()    依据国际时间来返回分钟(0-59)
getUTCSeconds()    依据国际时间来返回秒(0-59)
getUTCMilliseconds()依据国际时间来返回毫秒(0-999)
getTime()       返回从1970年1月1号0:0:0到现在一共花去的毫秒数
getTimezoneoffset() 返回时区偏差值,即格林威治平均时间(GMT)与运行脚本的计算机所处时区设置之间相差的分钟数)
parse(dateString)   返回在Date字符串中自从1970年1月1日00:00:00以来的毫秒数
setYear(yearInt)    设置年份.2位数或4位数
setFullYear(yearInt)设置年份.4位数
setMonth(monthInt) 设置月份(0-11)
setDate(dateInt)    设置日(1-31)
setHours(hourInt) 设置小时数(0-23)
setMinutes(minInt) 设置分钟数(0-59)
setSeconds(secInt) 设置秒数(0-59)
setMilliseconds(milliInt) 设置毫秒(0-999)
setUTCFullYear(yearInt) 依据国际时间来设置年份
setUTCMonth(monthInt) 依据国际时间来设置月(0-11)
setUTCDate(dateInt)     依据国际时间来设置日(1-31)
setUTCHours(hourInt)    依据国际时间来设置小时
setUTCMinutes(minInt) 依据国际时间来设置分钟
setUTCSeconds(secInt)    依据国际时间来设置秒
setUTCMilliseconds(milliInt)依据国际时间来设置毫秒
setTime(timeInt)    设置从1970年1月1日开始的时间.毫秒数
toGMTString()     根据格林威治时间将Date对象的日期(一个数值)转变成一个GMT时间字符串,如:Weds,15 June l997 14:02:02 GMT
toUTCString()     根据通用时间将一个Date对象的日期转换为一个字符串
toLocaleString()    把Date对象的日期(一个数值)转变成一个字符串,使用所在计算机上配置使用的特定日期格式
toSource()       显示对象的源代码
toString()       将日期对象转换为字符串
UTC(yyyy, mm, dd, hh, mm, ss, msec)返回从格林威治标准时间到指定时间的差距,单位为毫秒
valueOf()       返回日期对象的原始值

2.Math
属性:
constructor      所建立对象的函数参考
prototype       能够为对象加入的属性和方法
E           欧拉常量,自然对数的底(约等于2.718)
LN2          2的自然对数(约等于0.693)
LN10          10的自然对数(约等于2.302)
LOG2E         以2为底的e的对数.(约等于1.442)
LOG10E         以10为底的e的对数(约等于0.434)
PI           ∏的值(约等于3.14159)
SQRT1_2        1/2(0.5)的平方根(即l除以2的平方根,约等于o.707)
SQRT2         2的平方根(约等于1.414)

方法:
abs(x)     返回数字的绝对值
acos(x)    返回数字的反余弦值
asin(x)    返回数字的反正弦值
atan(x)    返回位于-PI/2 和 PI/2 的反正切值
atan2(y,x) 返回(x,y)位于 -PI 到 PI 之间的角度
ceil(x)    返回 x 四舍五入后的最大整数
cos(x)     返回一个数字的余弦值
exp(x)     返回 E^x 值
floor(x)    返回 x 四舍五入后的最小整数
log(x)     返回底数为E的自然对数
max(x,y)    返回 x 和 y 之间较大的数
min(x,y)    返回 x 和 y 之间较小的数
pow(x,y)    返回 y^x 的值
random()    返回位于 0 到 1 之间的随机函数
round(x)    四舍五入后取整
sin(x)     返回数字的正弦值
sqrt(x)    返回数字的平方根
tan(x)     返回一个角度的正切值
toSource() 显示对象的源代码
valueOf() 返回数学对象的原始值

3.Number
属性:
MAX_VALUE       The largest possible value a number in JavaScript can have 1.7976931348623157E+308
MIN_VALUE       The smallest possible value a number in JavaScript can have 5E-324
NaN          Equal to a value that is not a number.
NEGATIVE_INFINITY A value that is less than MIN_VALUE.
POSOTIVE_INFINITY A value that is greater than MAX_VALUE.
prototype       A static property of the Number object

方法:
toString       Returns a string representing the specified object
valueOf()      返回数学对象的原始值

4.Boolean
属性:
constructor 所建立对象的函数参考
prototype    能够为对象加入的属性和方法

方法:
toSource()    显示对象的源代码
toString()    将布尔值转换为字符串,并且返回结果
valueOf()    返回布尔对象的原始值


5.String
属性:
constructor 所建立对象的函数参考
prototype    能够为对象加入的属性和方法
length      返回字符串的字符长度

方法(20):
anchor("name")用来把字符串转换为HTML锚点标记内(<A NAME=>)
big()      把字符串中的文本变成大字体(<BIG>)
blink()     把字符串中的文本变成闪烁字体(<BLINK>)
bold()      把字符串中的文本变成黑字体(<B>)
fixed()     把字符串中的文本变成固定间距字体,即电报形式(<TT>)
fontcolor(color)设置字符串中文本的颜色(<FONT COLOR=>)
Fontsize(size) 把字符串中的文本变成指定大小(<FONTSIZE=>)
italics()    把字符串中的文本变成斜字体(<I>)
Link(url)用来把字符串转换-HTML链接标记中(<A HREF=>)
small()     把字符串中的文本变成小字体(<SMALL>)
strike()     把字符串中的文本变成划掉字体(<STRIKE>)
sub()      把字符串中的文本变成下标(subscript)字体((SUB>)
sup()      把字符串中的文本变成上标(superscript)字体(<SUP>)

charAt(index) 返回指定索引处的字符
charCodeAt(index)返回一个整数,该整数表示String对象中指定位置处的字符的Unicode编码
concat(string2)连接两条或多条字符串
fromCharCode(num1, num2, …, numN)获取指定的Unicode值并返回字符串
indexOf(searchString, startIndex) 返回字符串中第一个出现指定字符串的位置
lastlndexOf(searchString, startIndex) 返回字符串中最后一个出现指定字符串的位置
match(regex) 在字符串中查找指定值
replace(regex, newString)将字符串中的某些字符替换成其它字符
search(regex) 针对某执行值对字符串进行查找
slice(startIndex, endIndex)将部分字符抽出并在新的字符串中返回剩余部分
split(delimiter)将字符串分配为数组
substr(startIndex, length) 从startIndex取,取length个字符
substring(startIndex, endIndex) 从startIndex和endIndex之间的字符,不包括endIndex

toLowerCase() 把字符串中的文本变成小写
toUpperCase() 把字符串中的文本变成大写
toSource()    显示对象的源代码
valueOf()    返回字符串对象的原始值

6.Array
属性:
constructor 所建立对象的函数参考
prototype    能够为对象加入的属性和方法
index      For an array created by a regular expression match, the zero-based index of the match in the string.
input      For an array created by a regular expression match, reflects the original string against which the regular expression was matched.
length      获取数组元素的个数,即最大下标加1

方法(13):
concat(array1,arrayn)将两个或两个以上的数组值连接起来,合并后返回结果
join(string) 将数组中元素合并为字符串,string为分隔符.如省略参数则直接合并,不再分隔
pop()      移除数组中的最后一个元素并返回该元素
push(value) 在数组的末尾加上一个或多个元素,并且返回新的数组长度值
reverse()    颠倒数组中元素的顺序,反向排列
shift()     移除数组中的第一个元素并返回该元素
slice(start, deleteCount, [item1[, item2[,...[,itemN]]]]) 返从一个数组中移除一个或多个元素,如果必要,在所移除元素的位置上插入新元素,返回所移除的元素
sort(compare Function) 在未指定排序号的情况下,按照元素的字母顺序排列,如果不是字符串类型则转换成字符串再排序,返回排序后的数组
splice()     为数组删除并添加新的元素
toSource()    显示对象的源代码
toString()    将数组所有元素返回一个字符串,其间用逗号分隔
unshift(value)为数组的开始部分加上一个或多个元素,并且返回该数组的新长度
valueOf()    返回数组对象的原始值

7.RegExp
属性:
$1, ..., $9 Parenthesized substring matches, if any.
$_        See input.
$*        See multiline.
$&        See lastMatch.
$+        See lastParen.
$`        See leftContext.
$'        See rightContext.
global      Whether or not to test the regular expression against all possible matches in a string, or only against the first.
ignoreCase    Whether or not to ignore case while attempting a match in a string.
input      The string against which a regular expression is matched.
lastIndex    The index at which to start the next match.
lastMatch    The last matched characters.
lastParen    The last parenthesized substring match, if any.
leftContext The substring preceding the most recent match.
multiline    Whether or not to search in strings across multiple lines.
rightContext The substring following the most recent match.
source      The text of the pattern.

方法:
compile     Compiles a regular expression object.
exec       Executes a search for a match in its string parameter.
test       Tests for a match in its string parameter

8.Function
属性:
arguments    An array corresponding to the arguments passed to a function.
arity      Indicates the number of arguments expected by the function.
caller      Specifies which function called the current function.
prototype    Allows the addition of properties to a Function object.

方法:
toString     Returns a string representing the specified object.

9.Object
属性:
constructor Specifies the function that creates an object's prototype.
prototype    Allows the addition of properties to all objects.

方法:
eval       Evaluates a string of JavaScript code in the context of the specified object.
toString     Returns a string representing the specified object.
unwatch     Removes a watchpoint from a 属性源 the object.
valueOf     Returns the primitive value of the specified object.
watch      Adds a watchpoint to a 属性源 the object.

10.全局
属性:
Infinity     指定一个正负无穷大的数值
NaN       指定一个 “非数字” 值
undefined    指定一个未被赋值的变量

方法:
decodeURI()       为加密的URI进行解码
decodeURIComponent() 为加密的URI组件解码
encodeURI()       将字符串加密为URI
encodeURIComponent() 将字符串加密为URI组件
escape(string)      加密一个字符串
unescape()        使用escape()对一个字符串进行解码
eval(string)       判断一个字符串并将其以脚本代码的形式执行
isFinite(number)     检测一个值是否为一个有限数字,返回True或False
isNaN(string)      检测一个值是否不是一个有限数字
Number()         将一个对象的值转换为一个数字
parseFloat(string)    将一个字符串解析为一个浮点数字
parseInt(string)     将一个字符串解析为一个整数,不是四舍五入操作,而是切尾
String(object)      将一个对象值转换为一个字符串
number(object)

11.事件
属性:
a.窗口事件,只在body和frameset元素中才有效
onload      页面或图片加载完成时
onunload     用户离开页面时

b.表单元素事件,在表单元素中才有效
onchange     框内容改变时
onsubmit     点击提交按钮时
onreset     重新点击鼠标按键时
onselect     文本被选择时
onblur      元素失去焦点时
onfocus     当元素获取焦点时

c.键盘事件,在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title元素里都无效
onkeydown    按下键盘按键时
onkeypress    按下或按住键盘按键时
onkeyup     放开键盘按键时

d.在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title元素里都无效
onclick     鼠标点击一个对象时
ondblclick    鼠标双击一个对象时
onmousedown 鼠标被按下时
onmousemove 鼠标被移动时
onmouseout    鼠标离开元素时
onmouseover 鼠标经过元素时
onmouseup    释放鼠标按键时

e.其他
onresize     当窗口或框架被重新定义尺寸时
onabort     图片下载被打断时
onerror     当加载文档或图片时发生错误时


自定义对象:有初始化对象和定义构造函数的对象两种方法
a:初始化对象
例如: 对象={属性1:值1;属性2:值2;......属性n:值n} 注意:每个属性/值对之间用分号隔开;

b: 定义构造函数的对象
例如:
function 函数名(属性1, 属性2,......属性N){
this.属性1=属性值1;
this.属性2=属性值2;
this.属性n=属性值n;

this.方法名1=函数名1;
this.方法名2=函数名2;
}

注意:方法名和函数名可以同名,但是在方法调用函数前,函数必须已经定义好,否则会出错

为自定义的函数创建新的实例一样是使用 new 语句。

2012-1-30 11:34 Monday  
表单的验证一直是网页设计者头痛的问题,表单验证类 Validator就是为解决这个问题而写的,旨在使设计者从纷繁复杂的表单验证中解放出来,把精力集中于网页的设计和功能上的改进上。
    Validator是基于JavaScript技术的伪静态类和对象的自定义属性,可以对网页中的表单项输入进行相应的验证,允许同一页面中同时验证多个表单,熟悉接口之后也可以对特定的表单项甚至仅仅是某个字符串进行验证。因为是伪静态类,所以在调用时不需要实例化,直接以"类名+.语法+属性或方法名"来调用。此外,Validator还提供3种不同的错误提示模式,以满足不同的需要。
Validator目前可实现的验证类型有:
1.是否为空;
2.中文字符;
3.双字节字符
4.英文;
5.数字;
6.整数;
7.实数;
8.Email地址;
9.使用HTTP协议的网址;
10.电话号码;
11.货币;
12.手机号码;
13.邮政编码;
14.身份证号码(1.05增强);
15.QQ号码;
16.日期;
17.符合安全规则的密码;
18.某项的重复值;
19.两数的关系比较;
20.判断输入值是否在(n, m)区间;
21.输入字符长度限制(可按字节比较);
22.对于具有相同名称的单选按钮的选中判断;
23.限制具有相同名称的多选按钮的选中数目;
24.自定义的正则表达式验证;
25.文件上传格式过滤(1.04新增)。

更新历史:

1.01
修正对12月份的日期验证(感谢 flylg999 )

1.03
修正Range验证类型时将数字当字符串比较的bug(感谢 cncom 和 xtlhnhbb )
修正日期验证(感谢 Papsam )
增加Username验证类型
增加对Phone验证类型时支持分机号

1.04
增加文件格式的过滤,用于上传时限制上传的文件格式

1.05
增强对身份证号码的验证
运行环境(客户端):
在Windows Server 2003下用IE6.0+SP1和Mozilla Firefox 1.0测试通过;
在Lunix RedHat 9下的Netscape测试通过;

Validator 完整代码:

<script>
/*************************************************
Validator v1.05
code by 我佛山人
wfsr@msn.com
*************************************************/
Validator = {
Require : /.+/,
Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
Phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
Mobile : /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/,
Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
IdCard : "this.IsIdCard(value)",
Currency : /^\d+(\.\d+)?$/,
Number : /^\d+$/,
Zip : /^[1-9]\d{5}$/,
QQ : /^[1-9]\d{4,8}$/,
Integer : /^[-\+]?\d+$/,
Double : /^[-\+]?\d+(\.\d+)?$/,
English : /^[A-Za-z]+$/,
Chinese : /^[\u0391-\uFFE5]+$/,
Username : /^[a-z]\w{3,}$/i,
UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
IsSafe : function(str){return !this.UnSafe.test(str);},
SafeString : "this.IsSafe(value)",
Filter : "this.DoFilter(value, getAttribute('accept'))",
Limit : "this.limit(value.length,getAttribute('min'), getAttribute('max'))",
LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
Range : "getAttribute('min') < (value|0) && (value|0) < getAttribute('max')",
Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
Custom : "this.Exec(value, getAttribute('regexp'))",
Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
ErrorItem : [document.forms[0]],
ErrorMessage : ["以下原因导致提交失败:\t\t\t\t"],
Validate : function(theForm, mode){
var obj = theForm || event.srcElement;
var count = obj.elements.length;
this.ErrorMessage.length = 1;
this.ErrorItem.length = 1;
this.ErrorItem[0] = obj;
for(var i=0;i<count;i++){
with(obj.elements[i]){
var _dataType = getAttribute("dataType");
if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined") continue;
this.ClearState(obj.elements[i]);
if(getAttribute("require") == "false" && value == "") continue;
switch(_dataType){
case "IdCard" :
case "Date" :
case "Repeat" :
case "Range" :
case "Compare" :
case "Custom" :
case "Group" :
case "Limit" :
case "LimitB" :
case "SafeString" :
case "Filter" :
if(!eval(this[_dataType])) {
this.AddError(i, getAttribute("msg"));
}
break;
default :
if(!this[_dataType].test(value)){
this.AddError(i, getAttribute("msg"));
}
break;
}
}
}
if(this.ErrorMessage.length > 1){
mode = mode || 1;
var errCount = this.ErrorItem.length;
switch(mode){
case 2 :
for(var i=1;i<errCount;i++)
this.ErrorItem[i].style.color = "red";
case 1 :
alert(this.ErrorMessage.join("\n"));
this.ErrorItem[1].focus();
break;
case 3 :
for(var i=1;i<errCount;i++){
try{
var span = document.createElement("SPAN");
span.id = "__ErrorMessagePanel";
span.style.color = "red";
this.ErrorItem[i].parentNode.appendChild(span);
span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");
}
catch(e){alert(e.description);}
}
this.ErrorItem[1].focus();
break;
default :
alert(this.ErrorMessage.join("\n"));
break;
}
return false;
}
return true;
},
limit : function(len,min, max){
min = min || 0;
max = max || Number.MAX_VALUE;
return min <= len && len <= max;
},
LenB : function(str){
return str.replace(/[^\x00-\xff]/g,"**").length;
},
ClearState : function(elem){
with(elem){
if(style.color == "red")
style.color = "";
var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
if(lastNode.id == "__ErrorMessagePanel")
parentNode.removeChild(lastNode);
}
},
AddError : function(index, str){
this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
},
Exec : function(op, reg){
return new RegExp(reg,"g").test(op);
},
compare : function(op1,operator,op2){
switch (operator) {
case "NotEqual":
return (op1 != op2);
case "GreaterThan":
return (op1 > op2);
case "GreaterThanEqual":
return (op1 >= op2);
case "LessThan":
return (op1 < op2);
case "LessThanEqual":
return (op1 <= op2);
default:
return (op1 == op2);
}
},
MustChecked : function(name, min, max){
var groups = document.getElementsByName(name);
var hasChecked = 0;
min = min || 1;
max = max || groups.length;
for(var i=groups.length-1;i>=0;i--)
if(groups[i].checked) hasChecked++;
return min <= hasChecked && hasChecked <= max;
},
DoFilter : function(input, filter){
return new RegExp("^.+\.(?=EXT)(EXT)$".replace(/EXT/g, filter.split(/\s*,\s*/).join("|")), "gi").test(input);
},
IsIdCard : function(number){
var date, Ai;
var verify = "10x98765432";
var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
var area = ['','','','','','','','','','','','北京','天津','河北','山西','内蒙古','','','','','','辽宁','吉林','黑龙江','','','','','','','','上海','江苏','浙江','安微','福建','江西','山东','','','','河南','湖北','湖南','广东','广西','海南','','','','重庆','四川','贵州','云南','西藏','','','','','','','陕西','甘肃','青海','宁夏','新疆','','','','','','台湾','','','','','','','','','','香港','澳门','','','','','','','','','国外'];
var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/i);
if(re == null) return false;
if(re[1] >= area.length || area[re[1]] == "") return false;
if(re[2].length == 12){
Ai = number.substr(0, 17);
date = [re[9], re[10], re[11]].join("-");
}
else{
Ai = number.substr(0, 6) + "19" + number.substr(6);
date = ["19" + re[4], re[5], re[6]].join("-");
}
if(!this.IsDate(date, "ymd")) return false;
var sum = 0;
for(var i = 0;i<=16;i++){
sum += Ai.charAt(i) * Wi[i];
}
Ai += verify.charAt(sum%11);
return (number.length ==15 || number.length == 18 && number == Ai);
},
IsDate : function(op, formatString){
formatString = formatString || "ymd";
var m, year, month, day;
switch(formatString){
case "ymd" :
m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
if(m == null ) return false;
day = m[6];
month = m[5]*1;
year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
break;
case "dmy" :
m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
if(m == null ) return false;
day = m[1];
month = m[3]*1;
year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
break;
default :
break;
}
if(!parseInt(month)) return false;
month = month==0 ?12:month;
var date = new Date(year, month-1, day);
return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate());
function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
}
}
</script>

2012-1-30 11:26 Monday  
function bodyHeight(){
var cobj = document.body;
while(cobj.scrollTop == 0 && cobj.parentNode) {
   if(cobj.tagName.toLowerCase() == 'html') break;
   cobj = cobj.parentNode;
}
return cobj.clientHeight;
}
function scrolltop(){
var cobj = document.body;
while(cobj.scrollTop == 0 && cobj.parentNode) {
   if(cobj.tagName.toLowerCase() == 'html') break;
   cobj = cobj.parentNode;
}
return cobj.scrollTop;
}

 

 

不过以上在Jquery中就非常简单了,$(window).height()  + $(window).scrollTop();

鼠标Y event.clientY
鼠标X event.clientX

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>顶部展出的大幅广告</title>
   <script type="text/javascript" language="javascript">
    var time = 500;
    var h = 0;
    function addCount()
    {
        if(time>0)
        {
            time--;
            h = h+5;
        }
        else
        {
            return;
        }
        if(h>500) //高度
        {
            return;
        }
        document.getElementById("ads").style.display = "";
        document.getElementById("ads").style.height = h+"px";
        setTimeout("addCount()",30);
    }
   
    window.onload = function showAds()
    {
        addCount();
        setTimeout("noneAds()",7000); //停留时间自己适当调整
    }
    </script>
   
    <script type="text/javascript" language="javascript">
    var T = 500;
    var N = 500; //高度
    function noneAds()
    {
        if(T>0)
        {
            T--;
            N = N-5;
        }
        else
        {
            return;
        }
        if(N<0)
        {
            document.getElementById("ads").style.display = "none";
            return;
        }
       
        document.getElementById("ads").style.height = N+"px";
        setTimeout("noneAds()",30);
    }
    </script>
</head>
<body>
    <div id="ads" style="margin:auto; display:none; width:900px; top:0px; height:0px; border:solid 1px #000; background-color:#fafafa; overflow:hidden; text-align:center;">
        <a target="_blank" href="http://www.test.com">网页址:http://www.webjx.com</a>
    </div>
    <div style="margin:auto; width:900px; height:200px; border:solid 1px #000; background-color:#fafafa; text-align:center;">
        网站主体内容
    </div>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
<HEAD>
<TITLE>随滚动条移动的层</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html" charset="gb2312">
<META NAME="Author" CONTENT="haiwa">
<META NAME="homepage" CONTENT="www.danglinlin.cn">
</HEAD>
<style>
<!--
.div{
position: absolute;
border: 2px solid red;
background-color: #EFEFEF;
line-height:90px;
font-size:12px;
z-index:1000;
}
-->
</style>
<BODY>
<div id="Javascript.Div1" class="div" style="width: 240px; height:90px" align="center">正中...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc1(){
document.getElementById("Javascript.Div1").style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("Javascript.Div1").offsetHeight)/2)+"px";
document.getElementById("Javascript.Div1").style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("Javascript.Div1").offsetWidth)/2)+"px";
}
</SCRIPT>


<div id="Javascript.Div2" class="div" style="width: 240px; height:90px" align="center">左上...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc2(){
document.getElementById("Javascript.Div2").style.top=(document.documentElement.scrollTop)+"px";
document.getElementById("Javascript.Div2").style.left=(document.documentElement.scrollLeft)+"px";
}
</SCRIPT>

<div id="Javascript.Div3" class="div" style="width: 240px; height:90px" align="center">左下...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc3(){
document.getElementById("Javascript.Div3").style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Div3").offsetHeight)+"px";
document.getElementById("Javascript.Div3").style.left=(document.documentElement.scrollLeft)+"px";
}
</SCRIPT>

<div id="Javascript.Div4" class="div" style="width: 240px; height:90px" align="center">右上...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc4(){
document.getElementById("Javascript.Div4").style.top=(document.documentElement.scrollTop)+"px";
document.getElementById("Javascript.Div4").style.left=(document.documentElement.scrollLeft+document.documentElement.clientWidth-document.getElementById("Javascript.Div4").offsetWidth)+"px";
}
</SCRIPT>

<div id="Javascript.Div5" class="div" style="width: 240px; height:90px" align="center">右下...</div>
<SCRIPT LANGUAGE="JavaScript">
function sc5(){
document.getElementById("Javascript.Div5").style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Div5").offsetHeight)+"px";
document.getElementById("Javascript.Div5").style.left=(document.documentElement.scrollLeft+document.documentElement.clientWidth-document.getElementById("Javascript.Div5").offsetWidth)+"px";
}
</SCRIPT>


<SCRIPT LANGUAGE="JavaScript">
<!--
function scall(){
sc1();sc2();sc3();sc4();sc5();
}
window.onscroll=scall;
window.onresize=scall;
window.onload=scall;
//-->
</SCRIPT>
<div style="position: absolute; top: 0px; left: 0px; width: 10000px; height: 4000px;"></div>
</BODY>
</HTML>

2012-1-30 11:10 Monday  
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 3</title>
</head>
<body>
<script language="javascript">
document.body.oncopy = function ()   //当发生复制事件时触发函数,不管是ctrl+c还是右键-复制
{  
     setTimeout(  
         function ()  
         {  
             var text = clipboardData.getData("text");  
             if (text)  
             {  
                 text = text + "\r\n该文章转载自blog:"+location.href;  
                 clipboardData.setData("text", text);  
             }  
         },  
         100  
     )  
}  
window.onload = function()  
{  
     this.focus();    //内容加载完成后,获取焦点
}
</script>
sdfsdfsdf
</body>
</html>