读书人

javascript有关问题求教告诉

发布时间: 2013-01-17 10:28:54 作者: rapoo

javascript问题,求教告诉
图片上传错误提示:
Microsoft JScript 运行时错误: DOM Exception: INVALID_CHARACTER_ERR (5)
错误代码地址:

var io = document.createElement('<iframe id="' + frameId + '"name="' + frameId + '" />');


代码位置
createUploadIframe: function(frameId, uri) {
//create frame
if(window.ActiveXObject) {
var io = document.createElement('<iframe id="' + frameId + '"name="' + frameId + '" />');
if(typeof uri== 'boolean') {
io.src = 'javascript:false';
}
else if(typeof uri== 'string') {
io.src = uri;
}
} else {
var io = document.createElement('iframe');
io.id = frameId;
io.name = frameId;
}
io.style.display = 'none';

document.body.appendChild(io);

return io;
},

图片上传方法:
 //上传方法
function uploadFile(fileId) {

$("#uploading").ajaxStart(function () {
$(this).show();
}).ajaxComplete(function () {
$(this).hide();
});

$.ajaxFileUpload({
url: "/FileUpload/FileUpload?folderName=/UploadImages/BooKImages/",
secureuri: false,
fileElementId: fileId,
dataType: 'text',
success: function (data, status) {

if (data != "-1") {
$("#FILEPATH").val(data);
$("#ResultShow").html("上传成功!");
//$("#returnImg img").attr("src", data);
//$("#returnImg img").show();
$("#returnImg_show").attr("src", $("#FILEPATH").val());
// $("#returnImg_show").show();
// $("#regurnImg").html("<img id='returnImg_show'src='"+ data +"' alt='' style='display: none' />");
$("#returnImg").show();
}


else {
$("#ResultShow").html("上传失败!");
}

},
error: function (data, status, e) {
alert("发生错误!\n" + e);
},
extFields: {
user: 'guest',
comment: '好'
}
});

return false;
}

javascript IE9兼容性
[解决办法]
这样试试,现高版本的IE中iframe也不能用 src= 'javascript:.....'了


createUploadIframe: function(frameId, uri) {
//create frame

var io = document.createElement('iframe');
io.id = frameId;
io.name = frameId;
io.src = typeof uri== 'string'? uri:'';
io.style.display = 'none';
document.body.appendChild(io);
return io;
},

[解决办法]
貌似IE的createElement方法不支持HTML内容作为参数,1楼的方法应该可行。

读书人网 >JavaScript

热点推荐