我$("<div/>").text(value).html is not a function is not a function
在下面的代码中收到错误:
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
function startImageUpload(imageuploadform, imagefilename){
$('.imagef1_cancel').eq(window.lastUploadImageIndex).html(
'<div>' +
htmlEncode(imagefilename) +
'<button type="button" class="imageCancel" cancel_image_file_name="' +
imagefilename +
'">CANCEL</button><br/><hr/></div>'
);
$('.imagef1_cancel').eq(window.lastUploadImageIndex)
.find(".imageCancel")
.on("click", function(event) {
var cancel_image_file_name = $(this).attr('cancel_image_file_name');
console.log(cancel_image_file_name)
jQuery.ajax("cancelimage.php?imagefilename=" + cancel_image_file_name)
return stopImageUpload(2, cancel_image_file_name);
});
return true;
}
但我不明白的是,它与下面的代码非常相似。
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
function stopImageUpload(success, imagefilename) {
imagecounter++;
$('.listImage').eq(window.lastUploadImageIndex).append(
'<div>' +
htmlEncode(imagefilename) +
'<button type="button" class="deletefileimage" image_file_name="' +
imagefilename +
'">Remove</button><br/><hr/></div>'
);
var _imagecounter = imagecounter;
$('.listImage').eq(window.lastUploadImageIndex)
.find(".deletefileimage")
.on("click", function(event) {
var image_file_name = $(this).attr('image_file_name');
jQuery.ajax("deleteimage.php?imagefilename=" + image_file_name)
.done(function(data) {
$(".imagemsg" + _imagecounter).html(data);
}
);
$(this).parent().remove();
}
);
return true;
}
为什么会这样以及如何修复错误?