未捕获的SyntaxError:意外的令牌非法和SyntaxError:未终止的字符串文字

Uncaught SyntaxError: Unexpected token ILLEGAL and SyntaxError: unterminated string literal

本文关键字:SyntaxError 终止 字符串 文字 意外 令牌 非法      更新时间:2023-09-26

我的代码如下:

<!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"后,我收到"未捕获的SyntaxError:意外令牌非法"在Chrome和"SyntaxError:未终止的字符串文字"在Firefox。请帮忙查找错误

<!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