开发者

using ' in javascript code

I am using a tooltip plugin (qTip 2.0) and trying to specify content for the tooltip.

I get an error unterminated string literal

Here is the code:

<script type="text/javascript">
var $j = jQuery.noConflict();
$j('.tool').qtip({
content: 'Don\'t want...', 
position: {
  my: 'bottom left', 
  at: 'top left', 
  target: $j('.tool') 
  },
  style: {
  classes: 
  'ui-tooltip-dark ui-tooltip-shadow ui-tooltip-rounded ui-tooltip-tipsy'
}
});
</script>

In the Content you will see the word Don't I understand that JS will see the ' as an end to the content how do I get it to read Don't properly?

I have tried Don\'t and that did not work. I have tried changing ' to " and that did no开发者_StackOverflowt work.

I know there is a way around this I cannot remember though! Help!


Try putting double quotes around the content with the single quote, should fix it.

...
content: "Don't want...",
...

Does this help?


Use the escape character. Example:

var content = 'It\'s the escape character you want.';


Don't know why the escape character isn't working. But you could also try the HTML equivalent for the \ symbol

 &#92;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜