如何在JavaScript中显示双引号 [英] How to display double quotes in JavaScript

查看:142
本文介绍了如何在JavaScript中显示双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在html页面上,如果我用双引号命名,那么它没有被反映在页面上。它显示一个空白字符串。我尝试使用escape()函数,但是没有工作。那么用双引号显示一个字符串的方法是什么。

On html page if I give name in double quotes then it is not getting reflected on page. It displays a blank string. I tried with escape() function but that didn't work. So what is the way to display a string in double quotes.

有一件事我忘了提到我想在输入文本框中显示字符串。

One thing I forgot to mention that I want to display the string in input text box.

推荐答案

您有几个选项:

var str = 'My "String"'; //use single quotes for your string
var str = "My \"String\""; //escape your doublequotes
var str = "My "String""; //use it as html special chars

这篇关于如何在JavaScript中显示双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆