一:checkbox全选以及反选:

 

特殊

 

二:上传文件时显示缩略图

 

 

<script language="JavaScript">
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>= 120/80){
     
if(image.width>120){  
     ImgD.width
=120;
     ImgD.height
=(image.height*120)/image.width;
     }else{
     ImgD.width
=image.width;  
     ImgD.height
=image.height;
     }
     ImgD.alt
=image.width+"×"+image.height;
     }
    
else{
     
if(image.height>80){  
     ImgD.height
=80;
     ImgD.width
=(image.width*80)/image.height;     
     }else{
     ImgD.width
=image.width;  
     ImgD.height
=image.height;
     }
     ImgD.alt
=image.width+"×"+image.height;
     }
    }
   
/**//*else{
    ImgD.src="";
    ImgD.alt=""
    }
*/
   } 

function FileChange(Value){
flag
=false;
document.all.uploadimage.width
=10;
document.all.uploadimage.height
=10;
document.all.uploadimage.alt
="";
document.all.uploadimage.src
=Value;
}

function BeforeUpLoad(){
if(flag) alert("OK");else alert("FAIL");
}
    
</script>

    
<input style="width: 143px; height: 18px" type="file" size="8" name="pic" onchange="javascript:FileChange(this.value);">
    
<img id="uploadimage" height="10" width="10" src="" onload="javascript:DrawImage(this);"><br>
    
<button onclick="javascript:BeforeUpLoad();">
        提交
</button>
posted @ 2008-08-11 18:07 zhangsir 阅读(24) | 评论 (0)编辑

 

Code
posted @ 2008-08-05 14:58 zhangsir 阅读(51) | 评论 (0)编辑

 

using System.Text.RegularExpressions;

/// <summary>

  /// 去除HTML标记

  /// </summary>

  /// <param name="NoHTML">包括HTML的源码 </param>

  /// <returns>已经去除后的文字</returns>

  public static string NoHTML(string Htmlstring)

  { 

   //删除脚本

   Htmlstring = Regex.Replace(Htmlstring,@"<script[^>]*?>.*?</script>","",RegexOptions.IgnoreCase);

   //删除HTML

   Htmlstring = Regex.Replace(Htmlstring,@"<(.[^>]*)>","",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"([\r\n])[\s]+","",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"-->","",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"<!--.*","",RegexOptions.IgnoreCase);

   

   Htmlstring = Regex.Replace(Htmlstring,@"&(quot|#34);","\"",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(amp|#38);","&",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(lt|#60);","<",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(gt|#62);",">",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(nbsp|#160);"," ",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(iexcl|#161);","\xa1",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(cent|#162);","\xa2",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(pound|#163);","\xa3",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring,@"&(copy|#169);","\xa9",RegexOptions.IgnoreCase);

   Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);","",RegexOptions.IgnoreCase);

   Htmlstring.Replace("<","");

   Htmlstring.Replace(">","");

   Htmlstring.Replace("\r\n","");

   Htmlstring=HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

   return Htmlstring;

  }

posted @ 2008-07-24 10:38 zhangsir 阅读(18) | 评论 (0)编辑

一个项目需要动态处理客户端页面中图片的宽度,防止页面被过宽的图片撑变形。

过程就不叙说了。最终代码如下: 

<script language="javascript" type="text/javascript">
    window.onload
=function()
    {

         var imgWidthToLimit=580;          //对图片的限制宽度
         
var imgCongObj = ImgContainer.getElementsByTagName("IMG");     //获取id为ImgContainer的页面容器(div、table等)中的所有img对象
         
for( i=0;i<imgCongObj.length;i++)
         {
            
var image = new Image();
            image.src
=imgCongObj[i].src;
            image.i
=i;
            image.onreadystatechange
=function(){ 
                
if (image.readyState=="complete") { 
                    
var w= parseInt(image.width);
                    
if(w>imgWidthToLimit) imgCongObj[this.i].width=imgWidthToLimit;
                }
            } 
            
         }
    }                              
</script>    

 

 

 

 

 

 

参考资料:

<script>
var image = new Image();
image.src = 'http://www.baidu.com/img/logo.gif';
image.onreadystatechange=function(){
if (image.readyState=="complete") {
alert(["图片大小是:",image.width,image.height]);
}
}
</script>

解决了客户端图片没有加载而读取图片宽度时为0的问题。此法不稳定。后来我加到window.onload事件中  一切问题就解决了。

posted @ 2008-07-19 17:59 zhangsir 阅读(40) | 评论 (0)编辑
ceil函数

ceil函数的作用是求不小于给定实数的最小整数。

ceil(2)=ceil(1.2)=cei(1.5)=2.00


使用该函数需要包含头文件<math.h>,该函数返回值为浮点型


Run-Time Library Referenceceil, ceilfCalculates the ceiling of a value.


double ceil(
   double x
);
float ceil(
   float x
);  // C++ only
long double ceil(
   long double x
);  // C++ only
float ceilf(
   float x
);

Parameter
x
Floating-point value.
Return Value
The ceil function returns a double value representing the smallest integer that is greater than or equal to x. There is no error return.

Input SEH Exception Matherr Exception
± QNAN,IND none _DOMAIN

ceil has an implementation that uses Streaming SIMD Extensions 2 (SSE2). See _set_SSE2_enable for information and restrictions on using the SSE2 implementation.

Remarks
C++ allows overloading, so you can call overloads of ceil. In a C program, ceil always takes and returns a double.

Requirements
Routine Required header Compatibility
ceil, ceilf <math.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example
See the example for floor.

posted @ 2008-07-14 16:33 zhangsir 阅读(45) | 评论 (0)编辑
在as2.0中我们要得到flashvars中的值,比如说temp,我们用_root.temp就可以了。

在as3.0中我们用这样的方法:
var temp=this.loaderInfo.parameters["temp"];
posted @ 2008-07-09 16:33 zhangsir 阅读(69) | 评论 (0)编辑

在AS3中引入了标签,新的标签可以和循环体一起使用。例如,现在有两个嵌套的循环体,如果想要在内循环体中break掉外循环,一般使用下面的方法:

var i:Number;

var j:Number;

var exit:Boolean = false;

for (i=0; i<10; i++) {

    for (j=0; j<10; j++) {

        if (i > 3 && j > 3) {

            exit = true;

            break;

        }

    }

    if (exit) {

        break;

    }

}

在引入了新的标签以后,可以使用下面的方法从内循环体中直接break掉外循环体:

var i:Number;

var j:Number;

mainLoop: for (i=0; i<10; i++) {

    for (j=0; j<10; j++) {

        if (i > 3 && j > 3) {

            break mainLoop;

        }

    }

}

在第一个循环体上设置了mainLoop的标签,因此在循环体内任何地方使用break mainLoop直接中止外循环。

*检测鼠标离开Movie的动作

在以前的AS版本中,你无法做到检测鼠标是否还在Flash Movie上。因此影片不能检测到用户是否在关注着当前的Movie。另外一个问题是,如果使用了自定义的鼠标样式,在鼠标移出Movie后,自定义的鼠标还是继续停留在影片上,而不能正确的显示鼠标当前的位置。

现在,AS3允许你通过监听stage的mouseLeave行为来捕获鼠标移出Movie的动作。mouseLeave行为在鼠标移出Movie的时候执行。但是现在并没有mouseEnter事件,不过你可以通过使用mouseMove来设置。下面的例子中使用了一个方框来作为自定义的鼠标:

package {

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import flash.ui.Mouse;

    

    public class Test extends Sprite {

        

        private var cursor:Sprite = new Sprite();

        

        public function Test() {

            cursor.graphics.beginFill(0xFF);

            cursor.graphics.drawRect(0, 0, 25, 25);

            addChild(cursor);

            

            stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);

            stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);

            Mouse.hide();

        }

        

        public function cursorHide(evt:Event):void {

            cursor.visible = false;

        }

        

        public function cursorFollow(evt:MouseEvent):void {

            if (!cursor.visible) cursor.visible = true;

            cursor.x = stage.mouseX;

            cursor.y = stage.mouseY;

            evt.updateAfterEvent();

        }

    }

}

当鼠标离开Movie的时候,鼠标指针将被隐藏。当鼠标再次移动到Movie上的时候,mouseMove会被执行,然后显示鼠标。

posted @ 2008-07-09 12:32 zhangsir 阅读(19) | 评论 (0)编辑

最近用AS3写一些项目,在编程过程中,遇到不少问题,同时也有一些收获和心得。现在贴出来希望对大家在AS3编程有一些帮助。如果你发现有说得不对的地方,你可以指出来,大家一起来讨论。

1、AS3的强制类型转换

我之前一直以为是没有这个功能的,而最近在看一些文档,发现这个功能是有的。目前总结下来有两种写法:

  1. var loader:URLLoader = URLLoader(event.target);

     

    不知道这种写法是借鉴那种编程语言,反正我没有见过。

    补充这个语法说明:http://livedocs.adobe.com/flash/8_cn/main/00001211.html

  2. var loader:URLLoader = event.target as URLLoader;

     

    这种写法是借鉴VB.Net编程语言,唉!AS3语法真得一个大杂烩。

 

2、URLStream和URLLoader

URLStream在文本文件数据方面可以支持多种字符编码。

URLLoader在进过测试后,发现除UTF-8字符编码外,其他字符编码读过来的数据都是乱码。

可通过ByteArray对象字符编码转换(感谢abc12hjc提供补充代码):

public class MoxieAS extends Sprite

{

    public function MoxieAS ()

    {

        var stream:URLStream = new URLStream;

        

        stream.addEventListener(Event.COMPLETE, complete);

        stream.load(new URLRequest("ttt.xml"));  //  <root><a /><b /><c /></root>

    }

    

    private function complete (event:Event):void

    {

        var stream:URLStream = event.target as URLStream;

        var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));

        

        trace(xml.*.length());  //  output 3

    }

}

具体用那个方式就看实际功能需求了。

3、URLRequest

URLStream、URLLoader、Loader等读取外部数据的类,里的load方法参数值是URLRequest对象。我在编程过程总是喜欢直接写地址字符串,原来习惯改过来看样子要花点时间了。

4、Loader

在使用Loader来加载数据时,添加侦听事件时,注意一定要给Loader的 contentLoaderInfo属性增加事件,而不是给Loader对象增加事件。我就是因为加错对象(关键是编译时还没有报错),郁闷得差点要把电脑给扔了。

错误写法:

 var loader:Loader = new Loader(); 

 loader.addEventListener(Event.COMPLETE, completeHandler);

 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 

 loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

正确写法:

 var loader:Loader = new Loader();

 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

 loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

 loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

5、Loader加载过来的数据类型

大家知道Loader是用来代替原来 MovieClip的loadMovie功能,用于加载外部的图片文件,SWF文件。

  • 如果加载图片文件(jpg,gif,png等)时,Loader.content得到数据类型是Bitmap对象;
  • 如果加载SWF文件(flash 9 版本)时,Loader.content得到数据类型是MovieClip对象;
  • 如果加载SWF文件(flash 9 以前版本) 时, Loader.content得到数据类型是AVM1Movie对象;

 

6、stage

在调试flash过程发现,如果把swf文件放到html页面后,stage.stageWidth和stage.stageHeight在第一次加载调用时,他们的值为空值;

7、 AVM1Movie

如果是AVM1Movie 对象时,就不能直接调用stop,play,gotoAndStop等原来MovieClip对象的功能了,而且不能将AVM1Movie 对象转换成MovieClip对象。目前解决办法:一种是用flash cs3 重新生成 flash 9的swf文件;另一种是国外网站有说能AVM1和AVM2两个虚拟机相互调用的方式(贴一个地址);

8、mask

在使用遮罩功能,发现一个问题,如果不把用于遮罩的显示元件通过addChild方法添加到同一级的显示容器里的话,遮罩效果就显示不正常,不知道这个是不是一个bug。我差点因为这个问题而放弃AS3改用AS2了。


转自(http://blog.163.com/lihua61622137@126/blog/static/553499122007112832153684/

posted @ 2008-07-09 11:28 zhangsir 阅读(35) | 评论 (0)编辑
参考:http://livedocs.adobe.com/flash/9.0_cn/ActionScriptLangRefV3/flash/net/FileReference.html#event:uploadCompleteData
posted @ 2008-07-08 09:44 zhangsir 阅读(35) | 评论 (0)编辑