我的代码如下:
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"> </script>
<script type="text/javascript" src="uploadify/jquery.uploadify.min.js"></script>
<script>
function deleteFile(file_name) {
alert("Hello " + file_name);
}
$(function() {
$('#file_upload').uploadify({
'removeCompleted' : false,
'fileTypeDesc' : 'Image Files',
'fileTypeExts' : '*.gif; *.jpg; *.png',
'method' : 'post',
'queueSizeLimit' : '5',
'swf' : 'uploadify/uploadify.swf',
'uploader' : 'uploadimage.cgi',
'uploadLimit' : '5',
'onUploadSuccess': function(file, data, response) {
$(".imgpreview").append("<img src=\"" + data + "\" id=\"i" + file.id + "\" height=\"100px\" width=\"100px\" /><a onclick=\"alert('" + data + "')\">X</a>");
},
});
});
</script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css" />
</head>
<body>
<input type="file" name="file_upload" id="file_upload" />
<div class="imgpreview" id="imgpreview" style="height:100px;width:500px;border:2px solid;">
</div>
</body>
</html>
在屏幕上的图像旁边出现“X”时上传图像。点击链接'X'后,我在Chrome中收到“Uncaught SyntaxError:Unexpected token ILLEGAL”,在Firefox中收到“SyntaxError:unterminated string literal”。请帮忙找错。
答案 0 :(得分:-2)
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function delimg(img)
{
alert(img);
}
</script>
<script>
$(function() {
$('#file_upload').uploadify({
'removeCompleted' : false,
'fileTypeDesc' : 'Image Files',
'fileTypeExts' : '*.gif; *.jpg; *.png',
'method' : 'post',
'queueSizeLimit' : '5',
'swf' : 'uploadify/uploadify.swf',
'uploader' : 'uploadimage.cgi',
'uploadLimit' : '5',
'onUploadSuccess': function(file, data, response) {
data=$.trim(data);
$("#imgpreview").append("<img src='"+ data + "' width='75' height='75'/><a href='#' onclick=delimg('"+data+"')>Remove</a>'");
}
});
});
</script>
<script type="text/javascript" src="uploadify/jquery.uploadify.min.js"></script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css" />
</head>
<body>
<input type="file" name="file_upload" id="file_upload" />
<div class="imgpreview" id="imgpreview" style="height:100px;width:500px;border:2px solid;">
</div>
</body>
</html>
使用上面的代码,它将解决您的问题 - Naveen Thally