Home >Web Front-end >JS Tutorial >Solution to JavaScript unterminated string constant error under IE6_javascript tips

Solution to JavaScript unterminated string constant error under IE6_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:15:421454browse

It is mentioned that "DOM is UTF-8 encoding. If the JS library is not a separate independent JS file, but is included in the DOM, this problem will not occur. However, the separated JS file is not UTF-8 encoded , is added to the UTF-8 encoded DOM, Chinese characters will appear garbled, and the quotation marks will be affected, making the browser unable to determine the end of the string. The solution is very simple, just save the JS file in UTF-8 encoding format. . ”
So I modified the JavaScript reference,
After the modification, It can run normally and correctly. It seems that it is really a problem with the Chinese encoding format.
Problem: Although using gb2312 can solve the problem. But UTF-8 cannot. Further research is needed.

The project did not perform satisfactorily under IE6, which made me sweat. If someone hadn't used IE7, I wouldn't have been able to get angry even if I was extremely angry. The deception has passed, but the problem still needs to be solved. You must know that IE6 is still the main browser. After coming back, I used IE6 on the remote server to carefully check the erroneous JS library, and the prompt was "unterminated string constant". I wonder if I forgot to add a quote. Even if I forget to add a quote to end the string, the same error will occur under IE7 and FireFox. Why is it so good? After finding the line with the error, the truth came out...

I need an event to handle the user's click on the button and set the project warning information to "read" so that the warning information box will no longer pop up. Jquery will call the processing script and return processing information. If the processing information is true, it means the setting is successful. The JS code will specify the information element in the DOM to modify the HTML, that is, set "unread" to "read".

Copy code The code is as follows:

function setread(id){
$.post ("result/setRead.asp",{id:id},function(msg){
if(msg==true){
$("#msgList_" id).html("Read") ;//Error line.
}
});
}

The problem lies in this "read". Chinese, I was depressed for a long time. DOM is UTF-8 code. If the JS library is not a separate independent JS file, but is included in the DOM, this problem will not occur. However, the separated JS file is not UTF-8 encoded and is added to the UTF-8 encoded DOM. Chinese characters appear garbled and affect the quotation marks, making it impossible for the browser to determine the end of the string. The solution is very simple, just save the JS file as UTF-8 encoding format.

This little problem almost caused me great embarrassment in public.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn