在javascript中,我如何存储一个变量(来自数据库),其中包含引号和撇号

in javascript, how do I store in a variable (coming from a database) that contains both quotes and apostrophes?

本文关键字:数据库 包含引 变量 javascript 何存储 存储 一个      更新时间:2023-09-26

假设我使用这种语法:{column_name}:访问数据库,并且我想将其作为字符串存储在javascript上下文中。在数据包含撇号之前,使用var str = ':{column_name}:'可以很好地工作,引号也是如此,因为数据可能同时包含引号和撇号。我认为这是不可能的。你觉得呢?

可以使用'"''转义引号和撇号。例如:

var str = ''' is an apostrophe and '" is a quote';

var str = "'' is an apostrophe and '" is a quote";

请参阅http://www.w3schools.com/js/js_strings.asp

上的"特殊字符"部分。