如何在 JavaScript 中写引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5662108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:20:13  来源:igfitidea点击:

How to write quotation marks in JavaScript

javascripthtml

提问by john

Hi I want to do the following, but don't know how to write the quotation marks

您好,我想做以下操作,但不知道如何写引号

allSearchResults[0]="<li><a href="CXS101289/"> CXS101289/</a></li>";

It shall be quotation marks where the currently are.

当前所在的位置应为引号。

回答by Robert Koritnik

Two ways times two

两种方式乘以两次

  1. mix single and double quotes:

    // single outside, double inside quotes
    allSearchResults[0] = '<li><a href="CXS101289/">CXS101289/</a></li>';
    

    or

    // double outside, single inside quotes
    allSearchResults[0] = "<li><a href='CXS101289/'>CXS101289/</a></li>";
    
  2. use one set of quotes but escape inside ones:

    // double escaped quotes
    allSearchResults[0] = "<li><a href=\"CXS101289/\">CXS101289/</a></li>";
    

    or

    // single escaped quotes
    allSearchResults[0] = '<li><a href=\'CXS101289/\'>CXS101289/</a></li>';
    
  1. 混合单引号和双引号:

    // single outside, double inside quotes
    allSearchResults[0] = '<li><a href="CXS101289/">CXS101289/</a></li>';
    

    或者

    // double outside, single inside quotes
    allSearchResults[0] = "<li><a href='CXS101289/'>CXS101289/</a></li>";
    
  2. 使用一组引号但在里面转义:

    // double escaped quotes
    allSearchResults[0] = "<li><a href=\"CXS101289/\">CXS101289/</a></li>";
    

    或者

    // single escaped quotes
    allSearchResults[0] = '<li><a href=\'CXS101289/\'>CXS101289/</a></li>';
    

First approach with mixing is usually easier, because it presents less work since you only have to change the opening and closing quote.

第一种混合方法通常更容易,因为它提供的工作更少,因为您只需要更改开头和结尾的引号。

回答by Martin

Just escape the quotes inside the a tag.

只需转义 a 标签内的引​​号即可。

allSearchResults[0]="<li><a href=\"CXS101289/\"> CXS101289/</a></li>";

回答by Teneff

you can escape them like:

你可以像这样逃避它们:

allSearchResults[0]="<li><a href=\"CXS101289/\"> CXS101289/</a></li>";

or use the other quotes :

或使用其他引号:

allSearchResults[0]="<li><a href='CXS101289/'> CXS101289/</a></li>";

回答by Maurice Perry

allSearchResults[0]="<li><a href='CXS101289/'> CXS101289/</a></li>";

or

或者

allSearchResults[0]='<li><a href="CXS101289/"> CXS101289/</a></li>';

or

或者

allSearchResults[0]="<li><a href=\"CXS101289/\"> CXS101289/</a></li>";