一、在JavaScript中调用Flex方法
在Flex中可以用ExternalInterface来调用Flex的方法,途径是
1.通过在Flex应用可调用方法列表中添加指定的公用方法。在Flex应用中通过调用addCallback()可以把一个方法添加到此列表中。addCallback将一个ActionScript的方法注册为一个JavaScript和VBScript可以调用的方法。
addCallback()函数的定义如下:
addCallback(function_name:String, closure:Function):void
function_name参数就是在Html页面中脚本调用的方法名。closure参数是要调用的本地方法,这个参数可以是一个方法也可以是对象实例。

举个例子:
<mx:Script>
    import flash.external.*;
    public function myFunc():Number {
        return 42;
    }
    public function initApp():void {
        ExternalInterface.addCallback("myFlexFunction",myFunc);
    }
</mx:Script>

2.那么在Html页面中,先获得SWF对象的引用,也就是用<object .../>声明的Swf的Id属性,比如说是MyFlexApp。然后就可以用以下方式调用Flex中的方法。
<SCRIPT language='JavaScript' charset='utf-8'>
    function callApp() {
        var x = MyFlexApp.myFlexFunction();
        alert(x);
    }
</SCRIPT>
<button onclick="callApp()">Call App</button>



二、在Flex中调用 JavaScript
你 可以调用Html页面中的JavaScript,通过与JavaScript的交互,可以改变Style,调用远程方法。还可以将数据传递给Html页 面,处理后再返回给Flex,完成这样的功能主要有两种方法:ExternalInterface()和navigateToUrl()。
在Flex中调用JavaScript最简单的方法是使用ExternalInterface(),可以使用此API调用任意JavaScript,传递参数,获得返回值,如果调用失败,Flex抛出一个异常。
ExternalInterface封装了对浏览器支持的检查,可以用available属性来查看。
ExternalInterface的使用非常简单,语法如下:
flash.external.ExternalInterface.call(function_name: String[, arg1, ...]):Object;
参数function_name是要调用的JavaScript的函数名,后面的参数是JavaScript需要的参数。
举个例子说明如何调用JavaScript函数
Flex应用中,添加如下方法:
<mx:Script>
<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        import flash.external.*;
    
        public function callWrapper():void {
            var f:String = "changeDocumentTitle";
            var m:String = ExternalInterface.call(f,"New Title");
            trace(m);
        }
    </mx:Script>
    <mx:Button label="Change Document Title" click="callWrapper()"/>
</mx:Application>
Html页面中有如下函数定义:
<SCRIPT LANGUAGE="JavaScript">
    function changeDocumentTitle(a) {
        window.document.title=a;
        return "successful";
    }
</SCRIPT>

原文:http://www.blogjava.net/oathleo/archive/2008/04/11/192140.html

Posted on April 14, 2008 1:18 PM | | Comments (0) | TrackBacks (0)

<script language="JavaScript">
var AllowImgFileSize=2000;        //允许上传图片文件的大小 0为无限制  单位:KB
var AllowImgWidth=3000;            //允许上传的图片的宽度  0为无限制 单位:px(像素)
var AllowImgHeight=3000;            //允许上传的图片的高度  0为无限制 单位:px(像素)
function load(Obj){
    var tempImg=new Image();
    tempImg.onerror=function(){                   //不是图片
        thisform.button.disabled=true;            //提交不可用
        Obj.outerHTML=Obj.outerHTML;              //清除表单
        document.getElementById("err_msg").innerHTML="目标类型格式不正确或者图片已损坏!"
        document.getElementById("ErrMsg").innerHTML=""
    };

    tempImg.onreadystatechange=function(){
      thisform.button.disabled=false;          //提交可用
      document.getElementById("err_msg").innerHTML="&nbsp;&nbsp;&nbsp; 图片宽度:<font color=red>" +this.width + "</font><br>&nbsp;&nbsp;&nbsp; 图片高度:<font color=red>" + this.height + "</font><br>&nbsp;&nbsp;&nbsp; 图片大小:<font color=red>" + parseInt(this.fileSize/1024) + "K</font>";

        if(AllowImgWidth!=0&&AllowImgWidth<this.width ||AllowImgHeight!=0&&AllowImgHeight<this.height ||AllowImgFileSize!=0&&AllowImgFileSize*1024<this.fileSize ){
            document.execCommand("Delete");
            Obj.outerHTML=Obj.outerHTML;
            document.getElementById("ErrMsg").innerHTML="\n图片不要超过<font color=red>"+AllowImgFileSize+"</font>KB。<font color=red>"+AllowImgWidth+"</font>X<font color=red>"+AllowImgHeight+"</font>"
            thisform.button.disabled=true;
        }else{
            document.getElementById("ErrMsg").innerHTML=""
            document.all.err_msg.style.display='';
        }
    };
    tempImg.src=Obj.value;
}

function up(){
  if(thisform.button.disabled) event.returnValue=false;
}

var flag=false;
function DrawImage(ImgD){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
        {
    flag=true;
    if(image.width/image.height>= 350/300){
     if(image.width>350){
     ImgD.width=350;
     ImgD.height=(image.height*350)/image.width;
     }else{
     ImgD.width=image.width;
     ImgD.height=image.height;
     }
     }
    else
        {
     if(image.height>300)
         {
       ImgD.height=300;
       ImgD.width=(image.width*300)/image.height;
     }
         else
         {
     ImgD.width=image.width;
     ImgD.height=image.height;
     }
     }
    }
}
function FileChange(Value){
    flag=false;
    document.getElementById("uploadimage").width=0;
    document.getElementById("uploadimage").height=0;
    document.getElementById("uploadimage").alt="";
    document.getElementById("uploadimage").src=Value;
}
function mysub()
{
    esave.style.visibility="visible";
}

var i=11;
function addNew()
{
    tr=document.getElementById("t136").insertRow();
    tr.insertCell().innerHTML='图片说明<input type=text name=fileName>选择<input type=file name=pic'+i+' style=width:100 content Editable=false value onpropertychange=javascript:load(this); onchange=javascript:FileChange(this.value);><a href=javascript:void(0) onclick=del()>删除</a>'
}
function del()
{
    document.all.t136.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex);
}
</script>
<form name="thisform" action="/system/shopinfo/upimage.jsp" method="POST" onsubmit="javascript:up();" ENCTYPE="multipart/form-data">
<div id="esave" style="position:absolute; top:162px; z-index:10; visibility:hidden; width:210px; height:49px; left:24px">
   <marquee align="middle" scrollamount="5" width="210" height="50" style="background-color: #C0C0C0" behavior="alternate">...图片上传中...请等待...</marquee>
</div>

<table border="0" cellspacing="0" cellpadding="0" id="t136">
<tr>
  <td>
    图片说明<input type=text name=fileName>选择<input type=file name=pic1 style=width:100 content Editable=false onpropertychange=javascript:load(this); onchange=javascript:FileChange(this.value);><a href=javascript:void(0) onclick=del()>删除</a><br>
  </td>
</tr>
<tr>
  <td>
    图片说明<input type=text name=fileName>选择<input type=file name=pic1 style=width:100 content Editable=false onpropertychange=javascript:load(this); onchange=javascript:FileChange(this.value);><a href=javascript:void(0) onclick=del()>删除</a><br>
  </td>
</tr>
<tr>
  <td>
    图片说明<input type=text name=fileName>选择<input type=file name=pic1 style=width:100 content Editable=false onpropertychange=javascript:load(this); onchange=javascript:FileChange(this.value);><a href=javascript:void(0) onclick=del()>删除</a><br>
  </td>
</tr>
<tr>
  <td>
    图片说明<input type=text name=fileName>选择<input type=file name=pic1 style=width:100 content Editable=false onpropertychange=javascript:load(this); onchange=javascript:FileChange(this.value);><a href=javascript:void(0) onclick=del()>删除</a><br>
  </td>
</tr>
</table>
<input type="button" onclick="addNew()" value="增加一个上传>>">
<input type="submit" name="button" value="文件上传" disabled onclick="javascript:mysub()">
</form>

<p>图片说明是您所上所的图片的描叙信息,如果图片说明为空的话默认为文件的名称!</p>

<div id="err_msg">            </div>
<div id="ErrMsg">            </div>
<img id="uploadimage" height="0" width="0" src onload="javascript:DrawImage(uploadimage);">
<br>
(注:加入的图片文件大小不能超过1M,图片的长宽不能超过1280*1280!支持的图片类型有:gif,jpg)


把值传给父窗口:
<script>window.opener.document."&upload.form("FormName")&"."& upload.form("EditName")&".value='文件名.gif'</script>

Posted on February 18, 2008 12:39 PM | | Comments (0) | TrackBacks (0)

http://www.fckeditor.net/whatsnew

This is the most important release since FCKeditor 2.0. It introduces Safari and Opera compatibility, but also new features that leverage the quality of FCKeditor to an upper level. You will find no similar solution on other products.


The most exciting feature is the new Style System. Now you have full control over every single formatting and semantic command available in the editor interface. Why having a limited interface to achieve a XHTML 1.1 experience? Enjoy a full featured editor, while well controlling how things work on it. No more <font> tags? Well, the system is so flexible that it is up to you to decide (but don't worry... no <font> tags by default :).


Do you want more? What about blockquote support, the revamped Undo System, the Data Processor which makes it possible to handle non HTML data, and much more.

Tags:
Posted on December 4, 2007 11:22 PM | | Comments (0) | TrackBacks (0)

Ajax的兴起,给Javascript带来了新的生机,大量的javascript框架(Javascript Framework)层出不穷,一些框架来至于开发人员项目经验的总结和提炼,也有一些框架来至于商业公司,同时以开源和商业两种方式发布。借助这些框 架,可以大大加速Ajax项目的开发速度,但同时也面临不同的学习曲线,以及架构扩展性等等问题。如何选择Javascript框架,成为开发人员和架构 师头痛的一个问题。如果你正面临这样的问题,希望下面的几个建议对你在选择javascript框架上会有所帮助。

你的项目需求是什么

首 先要问自己这是一个什么项目,具体的需求是什么,是一个普通类型的网站还是一个在线的web应用程序,是否需要处理大量的键盘和鼠标事件,是否需要给用户 各类高级的ajax特性,还是说只要实现一个简单的异步页面刷新和一些简单dom操作,如果是后者,则可以选择一个相对简单的javascript框架, 封装基本的xmlhttprequest操作和dom操作就足够了。

浏览器的支持情况

不 同的框架兼容的浏览器会有所不同,尤其是一些高级的javascript框架,对低版本的浏览器都不支持,还有一些框架只支持ie和firefox,对其 他浏览器如opera、safari不支持。所以在框架的选择上还要考虑到系统的目标用户,如果目标用户都只使用ie6.0以上浏览器,那么在框架的选择 上余地就更大了。

框架后面是否有一个核心的开发团队

很多框架往往都是个人在业务时间开发的,随时可能停止更新,而如果后面有一个团队,则可以在一定程度上保准代码的更新,对bug和一些问题的及时响应,同时在代码质量上也相对有保准。

框架的成熟度

如果一个新的框架刚刚发布,使用的人往往不多,如果你贸然采用,在使用过程中遇到问题,可能要找个能帮你解决问题的人或者在网上找资料都显的很难。所以在这方面也要有所考虑。

框架的发布更新频率

一个框架有很高的发布更新频率说明新的功能在不断加入或者bug被fix的速度很快,反之一个框架半年都不出一个版本,基本可以说明这个框架已经不被开发者重视,很难得到新的发展。

文档的友好性

一个框架尤其是相对比较复杂的框架,如果没有充分和友好的文档,学习曲线会比较高,使用者在使用过程中往往需要通过阅读代码和其他外部的文章来学习怎么使用和解决一些问题。所以文档也是很重要的一个因素。

是否有个活跃的社区

一些成功的开源框架背后往往有一个社区在支撑,大家在里面交流使用经验,互相帮助解决使用过程中遇到的问题。任何问题,只要在这类社区中寻求帮助,往往很快就可以得到他人的帮助。这样的框架,即使一开始不是很成熟,也会很快发展起来。

框架的扩展性

在 实际的项目过程中,往往一个特定的框架是很难直接满足你的所有需求的,这就要求你需要去做一些定制和扩展的工作,如果一个框架没有很好的扩展性,则你可能 在项目后期为了实现某个特定的需求,不得不采用另一个新的框架,大大加大了项目的成本。所以选择一个有很好扩展性,如支持plugin等机制的框架,对你 今后系统的扩展会有很大的帮助。

性能和网络环境

不同的系统在性能和功能的侧重上会 有所不同,比如一个基于互联网的项目,可能考虑更多的是要求在保准性能的前提下,再来讲功能,很多高级的javascript框架往往在性能上不能让人满 意,一部分原因是封装了太多功能,导致js文件会非常大,在互联网环境下,下载这个js文件就会耗去不少时间,还有就是为了保准如框架的扩展性,往往做了 多层封装和抽象,在某种程度上其实是以牺牲部分性能为代价的。所以这样的框架可能更适合一些intranet内部的项目,而不是基于互联网的项目。
Posted on November 27, 2007 9:50 AM | | Comments (0) | TrackBacks (0)

<style>
.tableBorder7{width:800;solid; background-color: #000000;}
TD{font-family: 宋体;font-size: 12px;line-height : 15px ;}
th{background-color: #f7f7f7;color: #000000;font-size: 12px;font-weight:bold;}
th.th1{background-color: #333333;}
td.TableBody7{background-color: #B1EA45;}
</style>
<script language="JavaScript">
<!--
var pltsPop=null;
var pltsoffsetX = 10; // 弹出窗口位于鼠标左侧或者右侧的距离;3-12 合适
var pltsoffsetY = 15; // 弹出窗口位于鼠标下方的距离;3-12 合适
var pltsPopbg="#FFFFEE"; //背景色
var pltsPopfg="#111111"; //前景色
var pltsTitle="";
document.write('<div id=pltsTipLayer style="display: none;position: absolute; z-index:10001"></div>');

function pltsinits()
{
document.onmouseover = plts;
document.onmousemove = moveToMouseLoc;
}

function plts()
{ var o=event.srcElement;
if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
pltsPop=o.dypop;
if(pltsPop!=null&&pltsPop!=""&&typeof(pltsPop)!="undefined")
{
pltsTipLayer.style.left=-1000;
pltsTipLayer.style.display='';
var Msg=pltsPop.replace(/\n/g,"<br>");
Msg=Msg.replace(/\0x13/g,"<br>");
var re=/\{(.[^\{]*)\}/ig;
if(!re.test(Msg))pltsTitle="<font color=#ffffff>简介</font>";
else{
re=/\{(.[^\{]*)\}(.*)/ig;
pltsTitle=Msg.replace(re,"$1")+" ";
re=/\{(.[^\{]*)\}/ig;
Msg=Msg.replace(re,"");
Msg=Msg.replace("<br>","");}
//var attr=(document.location.toString().toLowerCase().indexOf("list.asp")>0?"nowrap":"");
var content =
'<table style="FILTER:alpha(opacity=90) shadow(color=#bbbbbb,direction=135);" id=toolTipTalbe border=0><tr><td width="100%"><table class=tableBorder7 cellspacing="1" cellpadding="0" style="width:100%">'+
'<tr id=pltsPoptop ><th height=18 valign=bottom class=th1 ><b><p id=topleft align=left><font color=#ffffff>↖</font>'+pltsTitle+'</p><p id=topright align=right style="display:none">'+pltsTitle+'<font color=#ffffff>↗</font></b></th></tr>'+
'<tr><td "+attr+" class=tablebody7 style="padding-left:14px;padding-right:14px;padding-top: 6px;padding-bottom:6px;line-height:135%">'+Msg+'</td></tr>'+
'<tr id=pltsPopbot style="display:none"><th height=18 valign=bottom class=th1><b><p id=botleft align=left><font color=#ffffff>↙</font>'+pltsTitle+'</p><p id=botright align=right style="display:none">'+pltsTitle+'<font color=#ffffff>↘</font></b></th></tr>'+
'</table></td></tr></table>';
pltsTipLayer.innerHTML=content;
toolTipTalbe.style.width=Math.min(pltsTipLayer.clientWidth,document.body.clientWidth/2.2);
moveToMouseLoc();
return true;
}
else
{
pltsTipLayer.innerHTML='';
pltsTipLayer.style.display='none';
return true;
}
}

function moveToMouseLoc()
{
if(pltsTipLayer.innerHTML=='')return true;
var MouseX=event.x;
var MouseY=event.y;
//window.status=event.y;
var popHeight=pltsTipLayer.clientHeight;
var popWidth=pltsTipLayer.clientWidth;
if(MouseY+pltsoffsetY+popHeight>document.body.clientHeight)
{
popTopAdjust=-popHeight-pltsoffsetY*1.5;
pltsPoptop.style.display="none";
pltsPopbot.style.display="";
}
else
{
popTopAdjust=0;
pltsPoptop.style.display="";
pltsPopbot.style.display="none";
}
if(MouseX+pltsoffsetX+popWidth>document.body.clientWidth)
{
popLeftAdjust=-popWidth-pltsoffsetX*2;
topleft.style.display="none";
botleft.style.display="none";
topright.style.display="";
botright.style.display="";
}
else
{
popLeftAdjust=0;
topleft.style.display="";
botleft.style.display="";
topright.style.display="none";
botright.style.display="none";
}
pltsTipLayer.style.left=MouseX+pltsoffsetX+document.body.scrollLeft+popLeftAdjust;
pltsTipLayer.style.top=MouseY+pltsoffsetY+document.body.scrollTop+popTopAdjust;
return true;
}
pltsinits();
//-->
</script>

</HEAD>

<BODY>
<div title="醉别西楼醒不记,春梦秋云,聚散真容易。<br>斜月半窗还少睡。画屏闲展吴山翠。<br>衣上酒痕诗里字,点点 行行,总是凄凉意。<br>红烛自怜无好计,夜寒空替人垂泪。">蝶恋花</div>
</BODY>
</HTML>

Posted on September 2, 2007 12:43 PM | | Comments (0) | TrackBacks (0)

JavaScript, aka Mocha, aka LiveScript, aka JScript, aka ECMAScript, is one of the world's most popular programming languages. Virtually every personal computer in the world has at least one JavaScript interpreter installed on it and in active use. JavaScript's popularity is due entirely to its role as the scripting language of the WWW.

JavaScript, 或者叫 Mocha,或者叫 LiveScript,或者叫 JScript,又或者叫 ECMAScript,是世界上最流行的编程语言之一。事实上世界上的每一台个人电脑都安装并在频繁使用至少一个JavaScript解释器。 JavaScript的流行完全是由于他在WWW脚本语言领域中的地位决定的。

Despite its popularity, few know that JavaScript is a very nice dynamic object-oriented general-purpose programming language. How can this be a secret? Why is this language so misunderstood?

尽管它很流行,但是很少有人知道JavaScript是一个非常棒的动态面向对象通用编程语言。这居然能成为一个秘密!这门语言为什么被误解如此之深?

The Name
名字

The Java- prefix suggests that JavaScript is somehow related to Java, that it is a subset or less capable version of Java. It seems that the name was intentionally selected to create confusion, and from confusion comes misunderstanding. JavaScript is not interpreted Java. Java is interpreted Java. JavaScript is a different language.

Java- 前缀很容易使人联想到Java,并认为它是Java的子集或简化版的Java。看起来最初给它选这个名字是别有用心的,是故意混淆概念、故意制造"误解" 的。JavaScript不是解释执行的Java。Java是解释执行的Java。JavaScript是另外一种语言。

JavaScript has a syntactic similarity to Java, much as Java has to C. But it is no more a subset of Java than Java is a subset of C. It is better than Java in the applications that Java (fka Oak) was originally intended for.

JavaScript的语法和Java有相似之处,这就像Java的语法和C很相像一样。但是它不是Java的子集,就像Java不是C的子集一样。它在Java(Oak)最初打算进军的领域中比Java更好。

JavaScript was not developed at Sun Microsystems, the home of Java. JavaScript was developed at Netscape. It was originally called LiveScript, but that name wasn't confusing enough.

JavaScript不是Sun Microsystems的产品,Sun是Java的家。JavaScript是在Netscape被开发出来的。它最初叫LiveScript,嗯……还是这个名字好。

The -Script suffix suggests that it is not a real programming language, that a scripting language is less than a programming language. But it is really a matter of specialization. Compared to C, JavaScript trades performance for expressive power and dynamism.

-Script后缀让人认为他不是一门真正的编程语言,和一门"编程语言"还有相当的差距。但是这只是应用领域的问题。和C相比,JavaScript是牺牲了性能但换来了丰富的表现力和灵活的形态。

Lisp in C's Clothing
披着C皮的Lisp

JavaScript's C-like syntax, including curly braces and the clunky for statement, makes it appear to be an ordinary procedural language. This is misleading because JavaScript has more in common with functional languages like Lisp or Scheme than with C or Java. It has arrays instead of lists and objects instead of property lists. Functions are first class. It has closures. You get lambdas without having to balance all those parens.

JavaScript的类C语法,包括大括号和语句的形式,让它看起来像普通的面向过程编程语言。这 是一种误解,因为JavaScript和函数式语言,比如 Lisp 或 Scheme,有更多的相似之处,而不是和C或Java。它使用数组而不是列表,使用对象而不是属性列表。函数是第一位的,它有闭包(closures 怎么翻译??),另外你还可以使用lambda表达式。

Typecasting
类型转换

JavaScript was designed to run in Netscape Navigator. Its success there led to it becoming standard equipment in virtually all web browsers. This has resulted in typecasting. JavaScript is the George Reeves of programming languages. JavaScript is well suited to a large class of non-Web-related applications

JavaScript最初被设计成在Netscape Navigator中运行,它在Navigator中的成功引领它成为事实上所有web浏览器的标准装备。这就造就了"类型转换"。JavaScript 是编程语言中的 George Reeves(超人),是大量非web程序的称职之选。

Moving Target
移动靶

The first versions of JavaScript were quite weak. They lacked exception handling, inner functions, and inheritance. In its present form, it is now a complete object-oriented programming language. But many opinions of the language are based on its immature forms.

JavaScript的最初几版非常弱,没有异常处理,没有内部函数和继承。现如今,它已经成为完全面向对象的编程语言。但是这门语言的许多思想是基于它不成熟的形式的。

The ECMA committee that has stewardship over the language is developing extensions which, while well intentioned, will aggravate one of the language's biggest problems: There are already too many versions. This creates confusion.

ECMA委员会,这门语言的管家,正在对它进行扩展,也在蓄意恶化它最大的问题:有太多的版本。这是混乱的根源。

Design Errors
设计上的错误

No programming language is perfect. JavaScript has its share of design errors, such as the overloading of + to mean both addition and concatenation with type coercion, and the error-prone with statement should be avoided. The reserved word policies are much too strict. Semicolon insertion was a huge mistake, as was the notation for literal regular expressions. These mistakes have led to programming errors, and called the design of the language as a whole into question. Fortunately, many of these problems can be mitigated with a good lint program.

没有什么编程语言是完美的。JavaScript也有它设计上的错误,比如重载的+号随着类型的不同既表示"相加"又表 示"连接",和本该避免的有错误倾向的 with 语句。它的保留字策略过于严格。分号的插入是一个巨大的错误,比如作为字面正则表达式的符号时。这些失误已直接导致编程中的错误,也使这门语言的整体设计 遭人质疑。还好,这些问题中有许多都可以在良好的 lint 程序中得以缓解。

The design of the language on the whole is quite sound. Surprisingly, the ECMAScript committee does not appear to be interested in correcting these problems. Perhaps they are more interested in making new ones.

这门语言的整体设计(上的问题)是相当明显的。奇怪的是ECMAScript委员会并没有对修正其中存在的问题表现出太大的兴趣,也许他们更热衷于制造新的问题。

Lousy Implementations
糟糕的实现

Some of the earlier implementations of JavaScript were quite buggy. This reflected badly on the language. Compounding that, those implementations were embedded in horribly buggy web browsers.

JavaScript的一些早期实现有许多bug,这反过来对语言本身产生了很坏的影响。更糟糕的是这些满是bug的实现是嵌入在满是bug的web浏览器中的。

Bad Books
糟糕的书

Nearly all of the books about JavaScript are quite awful. They contain errors, poor examples, and promote bad practices. Important features of the language are often explained poorly, or left out entirely. I have reviewed dozens of JavaScript books, and I can only recommend one: JavaScript: The Definitive Guide (4th Edition) by David Flanagan. (Attention authors: If you have written a good one, please send me a review copy.)

几乎所有的JavaScript书都是相当可怕的。它们包含错误,包含不好的例子,并鼓励不好的做法。 JavaScript语言的一些重要特性它们要么没有解释清楚,要么根本就没有提及。我看过很多JavaScript的书,但我只能推荐一本:David Flanagan著的 JavaScript: The Definitive Guide (4th Edition) (《JavaScript权威指南 第四版》)。(作者们请注意:如果你们写出了好书请发给我一份副本,我给你们校对。)

Substandard Standard
“准标准”的标准

The official specification for the language is published by ECMA. The specification is of extremely poor quality. It is difficult to read and very difficult to understand. This has been a contributor to the Bad Book problem because authors have been unable to use the standard document to improve their own understanding of the language. ECMA and the TC39 committee should be deeply embarrassed.

ECMA公布的官方语言规范的质量极其的差。不仅难读而且极其难懂。它可为那些"糟糕的书"做出了不小的贡献,因为那些作者无法通过这个标准文档来更深地理解这门语言。ECMA和TC39应该为此感到非常尴尬。

Amateurs
业余者

Most of the people writing in JavaScript are not programmers. They lack the training and discipline to write good programs. JavaScript has so much expressive power that they are able to do useful things in it, anyway. This has given JavaScript a reputation of being strictly for the amateurs, that it is not suitable for professional programming. This is simply not the case.

使用JavaScript的人大多不是程序员,他们缺少写良好程序的培训和训练。JavaScript有非常强大的表现力,不管怎样他们也能使用它做有用的事情。这给了JavaScript一个”全然适合业余爱好者而不适合专业程序员“的名声。这很明显是一个错误。

Object-Oriented
面向对象

Is JavaScript object-oriented? It has objects which can contain data and methods that act upon that data. Objects can contain other objects. It does not have classes, but it does have constructors which do what classes do, including acting as containers for class variables and methods. It does not have class-oriented inheritance, but it does have prototype-oriented inheritance.

JavaScript是面向对象的吗?它有对象,它的对象可以包含数据以及对数据进行操作的方法,对象也可以包含其他的对象。它没有类,但是它有构造函数来做类的事情,包括声明类的变量和方法。它没有面向类的继承,但是他有面向原型的继承。

The two main ways of building up object systems are by inheritance (is-a) and by aggregation (has-a). JavaScript does both, but its dynamic nature allows it to excel at aggregation.

构建对象系统的两大主要方法是继承(is-a)和聚合(has-a)。这两者JavaScript都有,但是它的动态天性允许有比聚合更好的实现方式。

Some argue that JavaScript is not truly object oriented because it does not provide information hiding. That is, objects cannot have private variables and private methods: All members are public.

一些关于JavaScript不是真的面向对象的争论其理由是它没有提供信息隐藏。也就是说JavaScript的对象没有私有变量和私有方法:它的所有成员都是公开的。

But it turns out that JavaScript objects can have private variables and private methods. (Click here now to find out how.) Of course, few understand this because JavaScript is the world's most misunderstood programming language.

但是事实是JavaScript 的对象可以有私有变量和私有方法(点击这里来看如何实现)。当然,之所以很少有人知道这个是因为JavaScript是世界上误解最深的语言嘛。

Some argue that JavaScript is not truly object oriented because it does not provide inheritance. But it turns out that JavaScript supports not only classical inheritance, but other code reuse patterns as well.

另一些关于JavaScript不是真的面向对象的争论其理由是它没有提供继承。但是事实是JavaScript不但支持经典的继承,而且支持其他一些代码重用的模式。

Copyright 2001 Douglas Crockford. All Rights Reserved Wrrrldwide.

Tags:
Posted on September 2, 2007 12:40 PM | | Comments (0) | TrackBacks (0)

一、验证类
1、数字验证内
  1.1 整数
  1.2 大于0的整数 (用于传来的ID的验证)
  1.3 负整数的验证
  1.4 整数不能大于iMax
  1.5 整数不能小于iMin
2、时间类
  2.1 短时间,形如 (13:04:06)
  2.2 短日期,形如 (2003-12-05)
  2.3 长时间,形如 (2003-12-05 13:04:06)
  2.4 只有年和月。形如(2003-05,或者2003-5)
  2.5 只有小时和分钟,形如(12:03)
3、表单类
  3.1 所有的表单的值都不能为空
  3.2 多行文本框的值不能为空。
  3.3 多行文本框的值不能超过sMaxStrleng
  3.4 多行文本框的值不能少于sMixStrleng
  3.5 判断单选框是否选择。
  3.6 判断复选框是否选择.
  3.7 复选框的全选,多选,全不选,反选
  3.8 文件上传过程中判断文件类型
4、字符类
  4.1 判断字符全部由a-Z或者是A-Z的字字母组成
  4.2 判断字符由字母和数字组成。
  4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
  4.4 字符串替换函数.Replace();
5、浏览器类
  5.1 判断浏览器的类型
  5.2 判断ie的版本
  5.3 判断客户端的分辨率
 
6、结合类
  6.1 email的判断。
  6.2 手机号码的验证
  6.3 身份证的验证

Continue reading "javascript 常用类"
Posted on August 28, 2007 9:32 AM | | Comments (0) | TrackBacks (0)

JavaScript excels at Modifying the DOM of a Web page, but we usually only do simple things with it, such as creating image rollovers, making tabs, etc. This article is going to show you how to create items on your page that you can drag and drop.

There are several reasons you might want to encorporate this Drag and Drop ability into your Web pages. One of the simplest reasons is to reorganize Data. As an example, you might want to have a queue of items that your users can reorganize. Instead of putting an input or select box next to each item to represent its order, you could make the entire group of items draggable. Or perhaps you want to have a navigation window on your site that can be moved around by your users. Then there's always the simplest reason: because you can!

There's really not much involved with dragging an item around on your Web page. First we have to know where the mouse cursor is, second we need to know when the user clicks on an item so that we know we should be dragging it, and finally we need to move the item.

http://www.webreference.com/programming/javascript/mk/column2/index.html

Tags:
Posted on August 13, 2007 4:06 PM | | Comments (0) | TrackBacks (0)

urlencode解码:
<script language=vbscript>
Function vbChar(str)
vbChar=chr(str)
End Function
Function uc(str)
  uc=hex(ascW(str))
End Function
</script>
<script language=javascript>
var glbEncode=new Array();
function reCode(str) {
  var str=str.replace(/%([A-Z].)%(.{2})/g,"@$1$2").replace(/\+/g,"%20");
  var t=str.split("@"),k,l=t.length;
for(var i=1;i<l;i++) {
  k=t.substring(0,4);
  if(!glbEncode[k])
  glbEncode[k]=uc(vbChar(eval("0x"+k)));
  t=glbEncode[k]+t.substring(4);
}
str=unescape(t.join("%u"));
return str;
}
document.write(reCode("%D0%A1+%C7%E0%2C%CE%D2%B0%AE%C4%E3"))
</script>
urlencode加码:
<script language=vbscript>
Function vbChar(str)
vbChar=chrW(str)
End Function
Function reHex(str)
reHex=hex(asc(str))
End Function
</script>
<script language=javascript>
var glbEncode=new Object();
function urlEncode(str) {
  str=escape(str).replace(/%u(.{4})/g,"@$1").replace(/%20/g,"+");
  var t=str.split("@"),l=t.length,k;
  for(var i=1;i<l;i++) {
    k=t.substring(0,4);
    if(!glbEncode[k])
    glbEncode[k]=reHex(vbChar(eval("0x"+k))).replace(/(.{2})(.{2})/g,"%$1%$2");
    t=glbEncode[k]+t.substring(4);
  }
  return t.join("");
}
var str="小 青,我爱你";
document.write(urlEncode(str))
</script>
原理:
urlencode跟escape除了空格和字符值大于 255 的编码不一样其他都一样
posted on 2006-10-16 00:49 汪杰 阅读(44) 评论(1)  编辑 收藏 引用 所属分类: ajax

FeedBack:
# re: 客户端的urlencode和dencode
2006-10-16 15:54 | 汪杰
<script language=vbscript>
Function vbChar(str)
vbChar=chr(str)
End Function
Function toHex(str)
toHex=hex(ascW(str))
End Function
</script>
<script language=javascript>
var glb=[];
function deUrlencode(str) {
str=str.replace(/%([A-Z].)%(.{2})/g,"@$1$2").replace(/\+/g,"%20");
var t=str.split("@"),l=t.length,k;
for(var i=1;i<l;i++) {
k=t.substring(0,4);
if(!glb[k])
glb[k]=toHex(vbChar(eval("0x"+k)));
t=glb[k]+t.substring(4);
}
return unescape(t.join("%u"));
}
alert(deUrlencode("%B7%EF%BB%CB"));
</script>

Posted on August 13, 2007 12:03 PM | | Comments (0) | TrackBacks (0)

asp 里面没有urldecode函数,好象aspx里有吧,我不太清楚,但asp里面还是用得很多。在网上查找了有别人写的urldecode函数,但是这个 函数有错误,而且在一些方面写得比较难理解。而且有错误,当里面有生僻双字节文字时就会产生错误,如“乄”经urlencoder后为“%81W”,解码 就不能成功。

其实双字节编码在这里只要把"W"也编成16进制ASC码就可以。

知识点:计算机里的cookie也是经过urlencode编码的,所以urldecode对破解cookie也很有用呵。

下面是源代码:

Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function

function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function

你用此方法解码“%81W”看看,可以了。

当然,你还可以玩点小段,使之成为自己的一种字符串加密方式。

Posted on August 13, 2007 12:02 PM | | Comments (0) | TrackBacks (0)
1 2 3 4 5 6 7 8 下一页
相关内容
广告计划
最新评论
[评论] 鸿雁 : 默默地为他们祈祷吧
[评论] lym328 : 客源CRM非常不错-----如有需要可以了解
[评论] kevinwu : 作用肯定是有的,Google会首先搜索站
[评论] ss : 其实还真的感觉不到sitemap的作用~
[评论] kevinwu : 谢谢你的关注 :-)
[评论] h51h : 贵博客写得非常的好,界面简洁但内
[评论] snguo : 这里很好 来这里支持下呢?
[评论] redondo : 感谢你分享知识! 这篇文章我转载到
[评论] kevinwu : 就是这本;看来我买的贵了点 - 8折;我
[评论] 安妮 : 《Flex3.0 RIA开发详解:基于ActionScript3.0