Question about the error of href writing javascript expressions in the link? -

Source: Internet
Author: User
The original code is as follows: the returned result is returned, but an error is reported on the console, and the historical rollback cannot be performed. The error text is UncaughtSyntaxError: Illegalreturnstatement. What is the problem with the front-end experts, it seems that the href attribute of the link cannot be written as a return expression. Of course, you may not write it like this. You just want to know why an error occurs. Why cannot I write a return expression in href? Thank you! The original code is as follows: the returned result is returned, but an error is reported on the console, and the historical rollback cannot be performed. The error text is Uncaught SyntaxError: Illegal return statement. Could you tell me the front-end experts, what is the problem? It seems that the href attribute of the link cannot be written as a return expression. Of course, you can not write it like this. You just want to know why an error occurs. Why can't you write a return expression in href? Thank you! Reply content: both of the existing answers are incorrect... I had to come up and answer it... Are you sure you want to solve this problem...



You must be aware that the following two types of code look like this, but the actual working principle is completely different:

Class A (href ):

Href = "javascript: your_code_here"> A Link
Return is a keyword, not an expression. It must appear in the function. Big Brother. js. Try to answer this question. please correct me.
The cause of the error is: When a "return" statement is executed in a non-function statement, it is considered invalid by js.

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.