最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - unterminated string literal error - Stack Overflow

programmeradmin2浏览0评论

I have placed the below code inside of the tag.

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('head').append('<script type="text/javascript" src="../wp-includes/js/thickbox.js"></script>');    
    });
</script>

I got an error of "unterminated string literal".

I have placed the below code inside of the tag.

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('head').append('<script type="text/javascript" src="../wp-includes/js/thickbox.js"></script>');    
    });
</script>

I got an error of "unterminated string literal".

Share Improve this question edited Jan 30, 2014 at 4:28 Balaji Kandasamy 4,50610 gold badges41 silver badges58 bronze badges asked Dec 11, 2010 at 16:47 A.C.BalajiA.C.Balaji 1,1135 gold badges13 silver badges23 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 10

The problem is ing from the fact that your code includes </script> in it. This is causing the browser to think that you're terminating your <script> tag early. If you change your code to the following, it will work:

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('head').append('<script type="text/javascript" src="../wp-includes/js/thickbox.js"></' + 'script>');    
    });
</script>

As you can see, the above code breaks the </script> in your string into '</' + 'script>', so that the browser doesn't parse it as a closing tag.

The code you posted doesn't have an unterminated string literal. The error means that you've started a string with a single or double quote, but don't have a second quote of the same kind to close the string.

"unterminated string literal error" is not a Javascript error.

It hints towards a PHP script error, though. Post that code and you shall receive help.

Balaji ,

Use jquery' getscript , its very nice way of doing it , it will append in head section and less changes of errors

http://api.jquery./jQuery.getScript/
发布评论

评论列表(0)

  1. 暂无评论