如何将引号传递给javascript函数 [英] How to pass quotation marks to javascript function
本文介绍了如何将引号传递给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个javascript函数,它接受包含引号的字符串并在输入字段中显示。但是这个函数不接受引号后的字符串
I have a javascript function which accepts strings which include quotation marks and displays in a input field. But this function does not accept the string after the quotation mark
function searchFormatter(cellvalue, options, rowObject) {
return '<input id="txt' + cellvalue + '" type="text" disabled="disabled" value="' + cellvalue + '" />';
}
例如。 21英寸==> 21
无论如何,我可以将引号传递给函数并打印它们。我不想替换他们。我想显示他们。
Is there anyway I can pass quotation marks to the function and print them. I don't want to replace them. I want to display them.
推荐答案
您必须转义特殊HTML字符如,
<
,>
。
例如:
You must escape special HTML characters like "
, <
, >
.
Eg:
function searchFormatter(cellvalue, options, rowObject) {
cellvalue = cellvalue.
replace(/&/g,'&').
replace(/>/g,'>').
replace(/</g,'<').
replace(/"/g,'"');
return '<input id="txt' + cellvalue + '" type="text" disabled="disabled" value="' + cellvalue + '" />';
}
这篇关于如何将引号传递给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文