一则基于 Jquery 的文件上传小插件

来源:互联网 发布:网络应急演练记录 编辑:程序博客网 时间:2024/06/08 15:25
$.fn.extend({    upload:function(_callback){    var html = "<form id='_ajaxFile' method='post' enctype='multipart/form-data' style='display:none;'><input type='file'></form>";    $('body').append(html);    $(this).bind('click',function(){    var postUrl = $(this).attr('data-url');    if(!postUrl){    alert('请为点击对象绑定一个 data-url 属性作为上传的地址!');    return false;}    popFileSelect(postUrl);});    $('#_ajaxFile > input').bind('change',function(){    $(this).parent().ajaxSubmit({    dataType:'json',    beforeSubmit:function(){    alert('before');},    success:_callback});});    function popFileSelect(url){$('#_ajaxFile').attr('action',url).find('input').click();    }}});$(function(){    $('.upload').upload(function(a){    $(this).css('border','1px solid red');});});

                                             
0 0