Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $(";div/>;).text(value).html不是函数错误_Javascript_Jquery_Dom - Fatal编程技术网

Javascript $(";div/>;).text(value).html不是函数错误

Javascript $(";div/>;).text(value).html不是函数错误,javascript,jquery,dom,Javascript,Jquery,Dom,我得到一个$(“”).文本(值).html不是下面代码中的函数错误: function htmlEncode(value) { return $('<div/>').text(value).html(); } function startImageUpload(imageuploadform, imagefilename){ $('.imagef1_cancel').eq(window.lastUploadImageIndex).html( '

我得到一个
$(“”).文本(值).html不是下面代码中的函数
错误:

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;
}
函数htmlEncode(值){
返回$('').text(value.html();
}
函数startImageUpload(imageuploadform,imagefilename){
$('.imagef1_cancel').eq(window.lastploadimageindex.html(
'' + 
htmlEncode(图像文件名)+
“取消”
);
返回true;
}
如何修复此错误?

的输出

$('<div/>').text(value)
$('').text(值)
是字符串而不是Jquery对象

你试过这个吗

$($('<div/>').text(value)).html();
$($('').text(value)).html();
的输出

$('<div/>').text(value)
$('').text(值)
是字符串而不是Jquery对象

你试过这个吗

$($('<div/>').text(value)).html();
$($('').text(value)).html();

我不确定你想要什么,但肯定是这行出错了

 return $('<div/>').text(value).html(); 
return$('').text(value).html();
如果要将该imagevalue封装在div中,只需使用|

function htmlEncode(value) { 
    return '<div><img src="'+value+'"/></div>'; //wrapping  it as an image most probably you want this
}
函数htmlEncode(值){
返回“”;//将其包装为图像很可能是您想要的
}

我不确定你想要什么,但肯定是这行出错了

 return $('<div/>').text(value).html(); 
return$('').text(value).html();
如果要将该imagevalue封装在div中,只需使用|

function htmlEncode(value) { 
    return '<div><img src="'+value+'"/></div>'; //wrapping  it as an image most probably you want this
}
函数htmlEncode(值){
返回“”;//将其包装为图像很可能是您想要的
}

代码本身工作正常:

您应该检查发送到函数中的字符串中是否有任何奇怪的内容,这些内容可能会扰乱所创建的代码。尽管我尝试了一些不同的值,您可以很容易地破坏生成的标记(因为您只在一个位置对值进行html编码,而不是在另一个位置),但是
htmlEncode
函数似乎仍然在运行时没有任何错误消息

您还可以检查
$.html
属性实际上仍然是一个函数,这样您就不会在某个地方意外更改它。字符串值返回函数代码:

alert($().html);

代码本身运行良好:

您应该检查发送到函数中的字符串中是否有任何奇怪的内容,这些内容可能会扰乱所创建的代码。尽管我尝试了一些不同的值,您可以很容易地破坏生成的标记(因为您只在一个位置对值进行html编码,而不是在另一个位置),但是
htmlEncode
函数似乎仍然在运行时没有任何错误消息

您还可以检查
$.html
属性实际上仍然是一个函数,这样您就不会在某个地方意外更改它。字符串值返回函数代码:

alert($().html);

美元(“”).text(value).html()中的“”是什么;您试图在此处返回的确切内容
$('').text(value).html()它只是返回的一个div标记,因此该值显示在它自己的div标记中。实际上,在运行代码时,我没有收到任何错误,但是为什么不将文件名连接到div,就像这样:“”+imageFileName+“”,为什么需要特殊的方法?@NaamaKatiee,因为我需要获取文件名并返回它,它似乎是用html.encode完成的。如果您查看我添加的第二个代码,那么它与delete按钮一起工作,而与cancel按钮不工作,后者在$('').text(value).html()中为'';您试图在此处返回的确切内容
$('').text(value).html()它只是返回的一个div标记,因此该值显示在它自己的div标记中。实际上,在运行代码时,我没有收到任何错误,但是为什么不将文件名连接到div,就像这样:“”+imageFileName+“”,为什么需要特殊的方法?@NaamaKatiee,因为我需要获取文件名并返回它,它似乎是用html.encode完成的。如果您查看我添加的第二个代码,那么它与“删除”按钮一起工作,与“取消”按钮不一起工作,它仅在使用
text()
时返回字符串。当您提供参数时,它返回一个
jQuery
对象。当您使用
text()
时,它只返回一个字符串。当您提供参数时,它返回一个
jQuery
对象。