开发者

unterminated string literal

Yet again, another one of these errors..

I've tried searching around to get this resolved before asking, but couldn't find anything that would fix this issue.

So I've got:(Updated)

<script type="text/javascript"> 
    $(function(){
        $('.episodes').live('click',function(){
            var id = $(this).attr('id').replace('episode_',''),
            width = 730,
            height = 645;

            if(id == 3){
                width = 635;
                height = 790;
            }                   

            ColdFusion.Window.create('Episode_'+id,'','/landing_pages/superhero/episode'+id+'.cfm',{width:width,height:height,center:true,draggable:false,resizable:false,modal:开发者_高级运维true});
        });
    });
</script>

I've tried escaping the "text\/javascript" and the <\/script>, but it'll either not work at all and not show the error anymore because it won't recognize it as a javascript statement or it will continue to throw the error.

Firebug is saying the problem is: var id = $(this).attr('id').replace('episode_',''),, but I'm not seeing where that could be a problem.

I was considering escaping the / in the create method at the bottom, but I wouldn't think it'd make a difference because it's showing the error is at the top.

Thanks!

(Update) I've tried all of the answers with the semi-colon issue, and it didn't work. Didn't impact it whatsoever. Any other ideas?

I'm actually pasting this into a CMS and it's going through SQL and then outputting it in my article. I don't see why it would cause a problem, but I guess it's another thing to consider.

UPDATED WITH FIX The error was the use of the single quotes. Had to change all of the single quotes to a double quote. Apparently that's something you've got to do when you're inserting it into the DB.

Final code is:

<script type="text/javascript"> 
    $(function(){
        $(".episodes").live("click",function(){
            var id = $(this).attr("id").replace("episode_",""),
            width = 730,
            height = 645;

            if(id == 3){
                width = 635;
                height = 790;
            }                   

            ColdFusion.Window.create("Episode_"+id,"","/landing_pages/superhero/episode"+id+".cfm",{width:width,height:height,center:true,draggable:false,resizable:false,modal:true});
        });
    });
</script>


try using semicolons:

<script type="text/javascript"> 
        $(function(){
            $('.episodes').live('click',function(){
                var id = $(this).attr('id').replace('episode_',''),
                var width = 730,
                var height = 645;

                if(id == 3){
                    width = 635,
                    height = 790;
                }                   

                ColdFusion.Window.create('Episode_'+id,'','/landing_pages/superhero/episode'+id+'.cfm',{width:width,height:height,center:true,draggable:false,resizable:false,modal:true})
            });
        });
    </script>


The error means that one of the single quotes in $('.episodes').live('click',function(){ isn't a single quote but something else (probably a back quote).

Try to replace all of them with double quotes (") because the ASCII encoding only contains one double quote but three different single quotes ('´`).


The problem exists in

var id = $(this).attr('id').replace('episode_',''),
    width = 730,
    height = 645

because it needs a semicolon at the end, not a comma.

var id = $(this).attr('id').replace('episode_',''),
    width = 730,
    height = 645;

Same goes for everything else inside of

if (id == 3) {...


your syntax is wrong, javascripts uses a ; to terminate a statement

thats the correct solution

$('.episodes').live('click', function() {
    var id = $(this).attr('id').replace('episode_', '');
    var width = 730;
    var height = 645;
    if (id == 3) {
        width = 635;
        height = 790;
    }
    ColdFusion.Window.create('Episode_' + id, '', '/landing_pages/superhero/episode' + id + '.cfm', { width: width, height: height, center: true, draggable: false, resizable: false, modal: true });
});

Edit

my bad, your syntax was right too.


When I check the code in JsLint, it doesn't complain about any unterminated strings, only that you omitted the semicolons at the end of each statement. That might however have some unexpected consequences, so it might very well be the reason for the error message.

Put semicolons at the end och each statement:

<script type="text/javascript"> 
  $(function(){
    $('.episodes').live('click',function(){
      var id = $(this).attr('id').replace('episode_',''),
      width = 730,
      height = 645;

      if(id == 3){
        width = 635;
        height = 790;
      }                   

      ColdFusion.Window.create('Episode_'+id,'','/landing_pages/superhero/episode'+id+'.cfm',{width:width,height:height,center:true,draggable:false,resizable:false,modal:true});
    });
  });
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜