简体   繁体   中英

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. 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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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