如何将引号传递给javascript函数
我有一个 javascript 函数,它接受包含引号的字符串并显示在输入字段中。但这个函数不接受引号后的字符串
function searchFormatter(cellvalue, options, rowObject) {
return '<input id="txt' + cellvalue + '" type="text" disabled="disabled" value="' + cellvalue + '" />';
}
Eg。 21" 英寸 ==> 21
无论如何,我可以将引号传递给函数并打印它们。我不想替换它们。我想显示 他们。
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 + '" />';
}
Eg. 21" Inch ==> 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须转义特殊 HTML 字符,例如
"
、<
、>
。例如:
You must escape special HTML characters like
"
,<
,>
.Eg:
您必须传递 cellValue 的值,如下所示
(
var cellValue = 21"(应为 21 后跟 " 后跟 ;(分号))
您可以在输入框中获取 21" 形式的值。
希望这有帮助。
You have to pass the value of the cellValue as shown below
(
var cellValue = 21"(Should be given as 21 followed by " followed by ;(semicolon))
You can get the value as 21" in the input box.
Hope this helps.
您需要将 " 替换为 "
使用此辅助方法:
You need to replace " with "
Use this helper method:
只需在创建输入元素时对值进行转义,然后对值进行转义即可正确显示。
简化示例:
just escape the value when creating the input element, and then unescape the value to display it correctly.
Simplified example:
您可以使用 Javascript 函数 escape() 对字符串进行编码,然后根据需要使用 unescape() 对其进行解码。
您还可以手动转义它们,如下例所示。
使用 \ 转义的引号作为字符串的一部分通过。
You can use the Javascript Functions escape() to encode a sting and then unescape() to decode them if needed.
You can also manually escape them like in the example below.
The quote escaped using \ goes through as a part of the string.