Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中转义单引号(')? [重复](How do I escape a single quote ( ' ) in JavaScript? [duplicate])

This question already has an answer here:(这个问题在这里已有答案:)

Single quote escape in JavaScript function parameters 6 answers(单引号转义JavaScript函数参数 6个答案)

UPDATE: I want to give an updated answer to this question.(更新:我想对这个问题给出一个更新的答案。)

First, let me state if you're attempting to accomplish what I have below, I recommend that you manage events by adding event listeners instead.(首先,让我说明如果您正在尝试完成下面的操作,我建议您通过添加事件侦听器来管理事件。) I highly recommend that you utilize jQuery for your project and use their syntax to manage event listeners over using DOM.(我强烈建议您为项目使用jQuery ,并使用它们的语法来管理使用DOM的事件监听器。) QUESTION() Okay, I am basically doing this:(好的,我基本上是这样做的:) document.getElementById("something").innerHTML = "<img src='something' onmouseover='change('ex1')' />"; I don't want double quotes (") where I put the \'. I only want a single quote, so I am trying to not make it put a double when it is used. I am trying to reach this in the final outcome.(我不想要双引号(“)我把它放在''。我只想要一个单引号,所以我试图在使用它时不要把它放一个双。我试图在最后的结果达到这个。) <img src="something" onmouseover="change('ex1')" /> Escaping isn't working for me.(逃避对我不起作用。) My marked answer works fine, however, the cleaner (and more professional-looking way, IMO) is loganfsmyth's answer .(我明确的答案很好,然而,更清洁(更专业的方式,IMO)是loganfsmyth的答案 。)   ask by Matthew translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to reply this article.

OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...