图片上传预览

//使用方法

<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/webPortal/js/imgPreview/CJL.0.1.min.js"></script>
    <script type="text/javascript" src="/webPortal/js/imgPreview/QuickUpload.js"></script>
    <script type="text/javascript" src="/webPortal/js/imgPreview/ImagePreviewd.js"></script>
<script type="text/javascript">
$(document).ready(function(){  
  
   
    var ip = new ImagePreview( $$("btn_tjwj"), $$("imgsrc"), {
        maxWidth: 100,
        maxHeight: 100,
        //action:        "ImagePreview.asp",
        onErr:        function(){ alert("载入预览出错!");},
        onCheck:    CheckPreview
});
ip.img.src = ImagePreview.TRANSPARENT;
ip.file.onchange = function(){ ip.preview(); };
$("img").attr("src","/webPortal/images/images01.jpg");


});
//检测程序
var exts = "jpg|gif|bmp", paths = "|";
function CheckPreview(){
    var value = this.file.value, check = true;
    if ( !value ) {
        check = false; alert("请先选择文件!");
    } else if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(value) ) {
        check = false; alert("只能上传以下类型:" + exts);
    } else if ( paths.indexOf( "|" + value + "|" ) >= 0 ) {
        check = false; alert("已经有相同文件!");
    }

    return check;
}

//下面包里是一个完整的jsp项目,我也是网上找的,做个笔计,以备用

你可能感兴趣的:(图片上传)