SCRIPT1015:加载字符串时未终止的字符串常量 [英] SCRIPT1015: Unterminated string constant when loading string

查看:985
本文介绍了SCRIPT1015:加载字符串时未终止的字符串常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我的`ASP.NET Razor v2 cshtml`文件中有这个代码,它应该将`string`加载到这个段落中,变量来自`c#list of strings`但是当加载的`string`包含类似的东西时这:

Hello I have this code in my `ASP.NET Razor v2 cshtml` file that should load `string` into this paragraph the variable is from `c# list of strings` but when the `string` that is loaded contains something like this:

+ "<p>"+'Rejv&#237;zsk&#225; 113 79001 Jesen&#237;k'+"</p>"



我收到这个JavaScript严重错误:`SCRIPT1015:未终止的字符串常量`



程序失败是因为某些角色逃过了我的`结束语录mar````



其实代码如下:


I get this JavaScript critical error: `SCRIPT1015: Unterminated string constant`

The program fails because some character escaped my `ending quotation mar` `'`

Actually the code looks like this:

"<p>"+'@string.Format(serviceDescription[i])'+"</p>"



serviceDescription是一个字符串列表,可能包含任何可以逃脱我的```的值。性格。



我可以知道如何解决这个问题吗?



此代码用于调整` Google API中的InfoWindow`



到目前为止,我尝试了非这些工作方法:


serviceDescription is list of strings that may containt whatever value that can escape my `'` character.

May I please know how to correct this?

This code is used in adjusting `InfoWindow in Google API`

So far I tried and non of these method worked:

+ "<p>"+' @string.Format("<p>{0}</p>", serviceDescription[i])'+"</p>"

+ "<p>"+'@string.Format(serviceDescription[i])'+"</p>"

+ "<p>"+'@string.Format("{0}", @Html.Raw(serviceDescription[i]))'+"</p>"

+ "<p>"+' @(new HtmlString(serviceDescription[i]))'+"</p>"

+ "<p>"+' @Html.Raw(serviceDescription[i])'+"</p>"

+ ' @Html.Raw("<p>"+@serviceDescription[i]+"</p>")'

+ @(new HtmlString("<p>"+serviceDescription[i]+"</p>"))

推荐答案

你可以使用html编码这个链接 http://www.naveen.com.au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289 [ ^ ]。



或者您可以使用此链接中描述的多个replace()http://jsperf.com/htmlencoderegex/25 []以及(使用Javascript删除换行符) http:// www.textfixer.com/tutorials/javascript-line-breaks.php [ ^ ]。希望这能帮到你
you can use the html encoding in this link http://www.naveen.com.au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289[^].

Or you can use multiple replace() as described in this link http://jsperf.com/htmlencoderegex/25[^] as well as (Remove Line Breaks with Javascript) in this link http://www.textfixer.com/tutorials/javascript-line-breaks.php[^]. Hope this help you


这篇关于SCRIPT1015:加载字符串时未终止的字符串常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆