一: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)编辑