简体   繁体   English

javascript将双引号转换为字符串中的单引号

[英]javascript convert double quotes into single quote in a string

I have a string which contains mix of single and double quotes. 我有一个包含单引号和双引号混合的字符串。 You can see here . 你可以在这里看到 First, If i try to make the jquery object of that string, i get break up of href and it's page link. 首先,如果我尝试创建该字符串的jquery对象,则会分解href和它的页面链接。 both parts behave like attributes of tag with an additional double quote attached with page's link part. 这两个部分的行为都类似于标签的属性,并在页面的链接部分附加了一个双引号。 like console of $(mystr)= ... href="" display.aspx""" where display.aspx is page's link. but if when i try href=\\'display.aspx\\', i'm able to get expected output. How do i get rid of this partition of attribute problem? code given on jsfiddle is 像$(mystr)= ... href =“” display.aspx“”“的控制台,其中display.aspx是页面的链接。但是,当我尝试href = \\'display.aspx \\'时,我能够预期的输出。我如何摆脱属性问题的这种划分?jsfiddle上给出的代码是

var s= "<tr role=\"row\" id=\"1\" tabindex=\"-1\" class=\"ui-widget-content jqgrow ui-row-ltr\"><td role=\"gridcell\" style=\"\" title=\"Albania\" aria-describedby=\"mytabl_Country\">Albania</td><td role=\"gridcell\" style=\"text-align:center;\" title=\"\" aria-describedby=\"mytabl_Nutrition related\"><img class=\"resultsGridImage\" src=\"Images/check.png\" oldtitle=\"Click on reference ID to view details:<ol><li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=241\">241</a>, Analyses of the situation and national action plan on food and nutrition for Albania 2003-2008</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=826\">826</a>, Towards a healthy country with healthy people - Public health and health promotion strategy</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=827\">827</a>, Analyses of the State of Food and Nutrition in Albania</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=828\">828</a>, Recommendation on healthy nutrition in Albania</li> </ol>\"></td></tr>";
console.debug($(s));
$('#btable').append(s);

perhaps I'm thinking to simplistic here, but this pops in mind when I look at the above code: 也许我想在这里简化一下,但是当我看上面的代码时,这会突然出现:

var s= "<tr role=\"row\" id=\"1\"....</tr>";

can be written as 可以写成

var s= "<tr role='row' id='1'...</tr>";

why use double quotes in your string? 为什么在字符串中使用双引号?

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

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