我有以下代码:
<!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:意外的令牌ILLEGAL”,而在Firefox中收到“ SyntaxError:unterminated字符串文字”。请帮助发现错误。
最佳答案
<!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