简体   繁体   English

显示带有单引号和/或双引号的文本

[英]Showing text with single quotes and/or double quotes

I have a variable of text, that can have single quotes or doubles quotes. 我有一个文本变量,可以有单引号或双引号。 For example in some cases. 例如在某些情况下。

`Estado 'mayor`' or  Esto dijo: "Ayer".

This text in some cases is taken from a Json, or a variable from database through .spring mvc. 在某些情况下,此文本取自Json,或者来自数据库的变量(通过.spring mvc)。

I tried with this: 我尝试了这个:

             try{
            descrp='${dataProvider.description}';
        }
        catch(err){
            descrp="${dataProvider.description}";
        }

but i have Uncaught SyntaxError: Unexpected identifier 但我有Uncaught SyntaxError:意外的标识符

And with: 与:

            try {
            alert(data.description);
            }
            catch(err){
             alert(data.description.replace("'", "\'"));    
            }

the same error. 同样的错误。 Is possible to do something for both cases? 两种情况下都可以做些什么吗? (singles quotes and doubles quotes) (单引号和双引号)

尝试使用escape() ,或在服务器端转换特殊字符(引号)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM