HTML and JS files are not using UTF-8 encoding causing some JS functions to execute incorrectly

Source: Internet
Author: User

When I wrote the front-end HTML page of the Windows application yesterday, I found a strange problem, a simple JS code, actually executed the error.

function Replacesymbol () {var val_exp = $ (' #calc_expression '). Val (); alert (val_exp); Val_exp=val_exp.replace (/(/g, ' (') Replace (/)/g, ') '). Replace (/x/g, ' * '). Replace (/÷/g, '/'); alert (val_exp); $ (' #calc_expression '). Val (val_exp);

The code is simple, that is, replacing the special characters in the expression, such as: () X÷ into the English state of the symbol, such as: () */

However, even if the above special characters are included, two alert results do not change. But the other functions in the same JS file perform normally.

Try to put this code into a separate HTML page, also perform normal.

This is obviously not a problem with this piece of code.


Then I think of it. js files are modified by the new TXT file extension, and the default is ANSI encoding. Try clicking on the menu bar in notepad++ format-to UTF-8 encoding format, save.

Execute again, OK.


Is the problem of this obscure coding format, has been tossing n long.

Later with a by VC + + to do JS friend chat about this, tell me: HTML, JS and database files, must be set to UTF-8 format, or later you have a headache!


A variety of languages and tools, desktop development and mobile development, there are all the pits, planted before you know oh.

Remember here, as a reminder!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.