2012-05-15 67 views
1

我正在一个$("<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; 
    } 

链接到应用程序,看看发生了什么事是在这里:application

+0

我认为不需要退货 –

+0

你得到什么价值? HTML或文本? – sree

回答

3
$('<div/>').html(value); //without text function 
1
function htmlEncode(value) { 
    return $('<div/>').text(value).html(); 
} 

如果上述代码段中的valueundefined,则text()返回DOM元素的文本内容,而不是元素本身,导致链接调用失败。

相关问题