JS上传图片问题 下面的代码改成只能上传一张图片,要是重新上传覆盖前一张 10
<script>jQuery(function(){var$=jQuery,$list=$('#filelist'),ratio=window.devicePixelRa...
<script>
jQuery(function() {
var $ = jQuery,
$list = $('#filelist'),
ratio = window.devicePixelRatio || 1,
thumbnailWidth = 100 * ratio,
thumbnailHeight = 100 * ratio,
uploader;
var uploader = WebUploader.create({
auto: true,
swf: '/static/default/wap/other/Uploader.swf',
server: '<{:U("public/upload",array("model"=>"life"))}>',
pick: '#filepicker',
accept: {
title: 'Images',
extensions: 'gif,jpg,jpeg,bmp,png',
mimeTypes: 'image/*'
}
});
uploader.on( 'fileQueued', function( file ) {
var $li = $('<div id="' + file.id + '" class="file-item thumbnail"><img></div>'),
$img = $li.find('img');
$list.append( $li );
uploader.makeThumb( file, function( error, src ) {
if ( error ) {
$img.replaceWith('<span>不能预览</span>');
return;
}
$img.attr( 'src', src );
}, thumbnailWidth, thumbnailHeight );
});
uploader.on( 'uploadSuccess', function( file,response ) {
$( '#'+file.id ).addClass('upload-state-done');
var pic = response['_raw'];
var str = '<input type="hidden" name="photo[photo]" value="' + pic + '" />';
$("#uploader").append(str);
});
uploader.on( 'uploadError', function( file ) {
var $li = $( '#'+file.id ),
$error = $li.find('div.error');
if ( !$error.length ) {
$error = $('<div class="error"></div>').appendTo( $li );
}
$error.text('上传失败');
});
});
</script>
-------------------------------------------------------
比如像这样
$(document).ready(function () {
$(document).on("click", ".photo img", function () {
$(this).parent().remove();
但是我不会弄。
html
<div id="uploader" class="uploader">
<div id="filepicker">选择图片</div>
<div id="filelist" class="uploader-list"></div> 展开
jQuery(function() {
var $ = jQuery,
$list = $('#filelist'),
ratio = window.devicePixelRatio || 1,
thumbnailWidth = 100 * ratio,
thumbnailHeight = 100 * ratio,
uploader;
var uploader = WebUploader.create({
auto: true,
swf: '/static/default/wap/other/Uploader.swf',
server: '<{:U("public/upload",array("model"=>"life"))}>',
pick: '#filepicker',
accept: {
title: 'Images',
extensions: 'gif,jpg,jpeg,bmp,png',
mimeTypes: 'image/*'
}
});
uploader.on( 'fileQueued', function( file ) {
var $li = $('<div id="' + file.id + '" class="file-item thumbnail"><img></div>'),
$img = $li.find('img');
$list.append( $li );
uploader.makeThumb( file, function( error, src ) {
if ( error ) {
$img.replaceWith('<span>不能预览</span>');
return;
}
$img.attr( 'src', src );
}, thumbnailWidth, thumbnailHeight );
});
uploader.on( 'uploadSuccess', function( file,response ) {
$( '#'+file.id ).addClass('upload-state-done');
var pic = response['_raw'];
var str = '<input type="hidden" name="photo[photo]" value="' + pic + '" />';
$("#uploader").append(str);
});
uploader.on( 'uploadError', function( file ) {
var $li = $( '#'+file.id ),
$error = $li.find('div.error');
if ( !$error.length ) {
$error = $('<div class="error"></div>').appendTo( $li );
}
$error.text('上传失败');
});
});
</script>
-------------------------------------------------------
比如像这样
$(document).ready(function () {
$(document).on("click", ".photo img", function () {
$(this).parent().remove();
但是我不会弄。
html
<div id="uploader" class="uploader">
<div id="filepicker">选择图片</div>
<div id="filelist" class="uploader-list"></div> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询