[英]I am getting a 'this is not a function' error
我得到一個$("<div/>").text(value).html is not a function
在下面的代碼中$("<div/>").text(value).html 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></div>'
);
return true;
}
如何解決這個錯誤?
奇怪的是我下面有類似的代碼,但功能不同(stopImageUpload),代碼工作正常如下:
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>'
);
return true;
}
鏈接到應用程序以查看正在發生的事情在這里: 應用程序
$('<div/>').html(value); //without text function
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
如果value
在上面的代碼片段是undefined
,那么text()
返回DOM元素的文本內容,而不是元素本身,引起鏈式調用失敗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.