简体   繁体   English

在JS中用双引号替换单引号

[英]Replacing single quotes with double quotes in JS

We are currently in the process of translating our VBScript to javascript and one of the steps is to remove single quotes ' and use double quotes instead " . 目前,我们正在将VBScript转换为javascript,其中一个步骤是删除单引号'并使用双引号代替"

I have the following line of code in the HTML header: 我在HTML标头中包含以下代码行:

document.write("<div style='position:absolute;padding-left:10px;padding-top:50px;color:red;font-size:13pt' id='divtest'><%=resxPleaseWait%><marquee style='border-top:solid 1px black' DIRECTION=RIGHT BEHAVIOR=SCROLL SCROLLAMOUNT=10 SCROLLDELAY=200>.</marquee>  </div>")

This used to be VB script but is now being written as JS. 这曾经是VB脚本,但现在被编写为JS。

Further down the page the ID divtest is called. 在页面的更下方,将调用ID divtest In replacing the single quotes this functionality breaks and I cannot think of an alternative. 在替换单引号时,此功能中断了,我无法想到替代方法。 Any ideas? 有任何想法吗?

You can use DoubleQuotes " in your javascript by escaping them like this \\". 您可以在JavaScript中使用DoubleQuotes“,方法是将\\\\这样转义为\\”。

document.write("<div style=\"position:absolute;padding-left:10px;padding-top:50px;color:red;font-size:13pt\" id=\"divtest\"><%=resxPleaseWait%>  <marquee style=\"border-top:solid 1px black\" DIRECTION=\"RIGHT\" BEHAVIOR=\"SCROLL\" SCROLLAMOUNT=\"10\" SCROLLDELAY=\"200\">.</marquee>  </div>")

The errors you are experiencing may have been caused by not placing quotes around the marquee properties. 您遇到的错误可能是由于未在字幕属性周围放置引号引起的。 I corrected this too in the above code. 我也在上面的代码中更正了此问题。

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

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