开发者

How to get a Clean String in Javascript?

i have a long String. With some German characters and lots of new lines tabs ect.. In a Selectbox user can select a text, on change i do

document.getElementById('text').value=this.value;

But this fails. I just get a "unterminated string literal" as error in JavaScript.

I think i should clean the string.开发者_StackOverflow中文版

How can i do it in JavaScript?


Its not because of that code, there is syntax error somewhere in your javascript file.

For example, in one of your previous question's answer

 alert("yes link clicked); 

You could see, there is " is missing after clicked, which could cause unterminated string literal error. Fix it like

 alert("yes link clicked"); 


As I cannot judge from your code, you might want to check what this in this.value refers to, e.g. using an alert("debug: " + this.value) .

Other than that, you might want to use encodeURI() for converting umlauts and other special characters to hexadecimal notation. If your page's content-type is set to UTF-8 special characters will then display correctly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜