經(jīng)典美文

5U文學(xué)網(wǎng) > 美文 > 經(jīng)典美文 > stringliteralisunterminated的簡單介紹

stringliteralisunterminated的簡單介紹

| admin

Firefox瀏覽器每次打開新標(biāo)簽頁時,都彈出javascript應(yīng)用程序Error: unterminated string literal

尊敬的用戶,您好!很高興為您答疑

這個彈出框肯定不是firefox自帶的,據(jù)分析可能是如下2種原因造成:

1、您之前安裝了某種插件并損壞,故在新建標(biāo)簽時彈出錯誤句柄;

2、您的系統(tǒng)被病毒感染,而您進(jìn)行過查殺,誤刪了部分必要文件,導(dǎo)致瀏覽器新建標(biāo)簽時調(diào)用出錯。

希望我的回答對您有所幫助,如有疑問,歡迎繼續(xù)咨詢我們。

親們,這句有錯嗎?報這個錯誤:unterminated string literal

Javascript使用document.write(str)進(jìn)行輸出時,常提示下列錯誤:Error: unterminated string literal。

通常原因是輸出字符str中包含換行符導(dǎo)致的。

建議將"替換成' 同一個字符串 不要手動換行。

百度編輯器unterminated string literal怎么解決

nterminated string literal提示,我百度了一下,發(fā)現(xiàn)是js中單引號、雙引號、換行、回車 都是違反json規(guī)范,下面我們來處理一下。

template/bbs/post_run.htm

找到這段

var word_tpl = 'div class="pop_sensitive"\

div class="pop_top J_drag_handle"\

a href="#" class="pop_close J_close"關(guān)閉/a\

strong提示/strong\

/divdiv class="pop_cont"\

div class="not_content_mini" id="J_word_tip"/div\

/div\

div class="pop_bottom" id="J_word_bototm"/div\

/div',

改成

var word_tpl = 'div class="pop_sensitive"div class="pop_top J_drag_handle"a href="#" class="pop_close J_close"關(guān)閉/astrong提示/strong/divdiv class="pop_cont"div class="not_content_mini" id="J_word_tip"/div/div div class="pop_bottom" id="J_word_bototm"/div/div',

php unterminated string literal怎么解決

javascript使用document.write(str)進(jìn)行輸出時,常提示下列錯誤:

Error: unterminated string literal。通常原因是輸出字符str中包含換行符導(dǎo)致的。

解決方法如下:

asp:

str=replace(str,vbcrlf,"",1,-1,1)

php:

$str = str_replace("\n", "", $str);

$str = str_replace("\r", "", $str);

然后再進(jìn)行document.write(str)輸出。

注:

jsp的對應(yīng)函數(shù):

public static final String htmlToCode(String s)

{

if(s == null)

{

return "";

} else

{ s = s.replace("\n\r", "br ");

s = s.replace("\r\n", "br ");//這才是正確的!

s= s.replace("\t", " ");

s =s.replace(" ", " ");

s=s.replace("\"", "\\"+"\"");//如果原文含有雙引號,這一句最關(guān)鍵!?。。。?!

return s;

}

}

如果這樣寫報錯

s = s.replace("\n\r", "br ");

s = s.replace("\r\n", "br ");//這才是正確的!

s= s.replace("\t", " ");

s =s.replace(" ", " ");

s=s.replace("\"", "\\"+"\"");//如果原文含有雙引號,這一句最關(guān)鍵?。。。。。?/p>

不加最后一句就會無法判斷雙引號報錯,注意最后一句是用\"替換“,但是注意轉(zhuǎn)義字符寫法?。。?/p>

這是普通的解決方法,另外一種保留回車的方法

先將\r\n替換為br,然后再將\r與\n替換掉,而不是簡單的舍棄為‘’。

function my_nl2br($s)

{

return str_replace("\n",'br',str_replace("\r",'br',str_replace("\r\n",'br',$s)));

}

unterminated string literal錯誤怎么解決

[html] view plain copy

select name="${item.name}" id="${item.id}" style="${item.styles}" class="commonInput longtext ${item.classes}"

option value="${item.value}"

/option

/select

因此在后臺用replaceAll方法轉(zhuǎn)換了"" ,""。

然后頁面接收了一下:

[javascript] view plain copy

script type="text/javascript"

var isModify = "${isModify}";

if(isModify == 1){

document.getElementById("textarea1").innerHTML = "${contentTemp}";

alert("success");

}

/script

然后在firebug里報錯鳥,unterminated string literal

Other...

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

在使用replaceAll()方法時需要注意,要用一個值去接收才能獲取到轉(zhuǎn)換后的字符串??磖eplaceAll()的API:

String java.lang.String.replace(CharSequence target,CharSequence replacement)

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

Parameters:

target The sequence of char values to be replaced

replacement The replacement sequence of char values

Returns:

The resulting string

Throws:

我一開始直接

[java] view plain copy

content.replaceAll("", "").replaceAll("", "");

還以為直接這樣content內(nèi)容就會變了。。。怎么運行都不對。。。。(╯‵□′)╯︵┻━┻

媽蛋真是被自己蠢哭了。。。QAQ

---------------------------------------------------------------------------------------------------------------------------------------------------------------

發(fā)現(xiàn)問題是因為換行識別不了,不是一個完整的字符串,因此需要將/r/n轉(zhuǎn)換一下。

[java] view plain copy

@Override

protected String handleEdit(HttpServletRequest request,

HttpServletResponse response, Long objectId) throws Exception {

if(objectId != null ){

Element element = elementManager.getByObjectId(objectId);

String temp = element.getContent().replaceAll("", "").replaceAll("", "");

temp = temp.replace("\"", "\\"+"\"");

temp = temp.replaceAll("\r\n", "br ");

request.setAttribute("contentTemp", temp);

request.setAttribute("isModify", 1);

}

return super.handleEdit(request, response, objectId);

}

[java] view plain copy

temp = temp.replace("\"", "\\"+"\""); //轉(zhuǎn)換引號

temp = temp.replaceAll("\r\n", "br "); //轉(zhuǎn)換換行

OK....終于能正常顯示了。

數(shù)據(jù)庫里是這樣的:

218130