Table of Contents
回复内容:
Home Web Front-end H5 Tutorial 关于链接中href写javascript表达式出现的错误疑问?

关于链接中href写javascript表达式出现的错误疑问?

Jun 07, 2016 am 08:41 AM
href return syntaxerror

原代码是这样的:返回 但是这个却在控制台报了个错,然后无法进行历史回退; 错误文本:Uncaught SyntaxError: Illegal return statement 请问下前端大神们,这个是什么问题,貌似链接的href属性不能写return表达式,当然可以不这样写的,就是想知道为什么会出错,为什么href不能写return表达式 先谢谢了!

回复内容:

已有的两个回答都是错的。。。只好冒出来回答一下。。。童鞋你们这样不求甚解真的好吗。。。



要深刻认识到,以下两种代码看起来像,但是实际作用原理完全不同:

A类(href):
<span class="nt"><a</span> <span class="na">href=</span><span class="s">"javascript:your_code_here"</span><span class="nt">></span> A Link <span class="nt"></a></span>
Copy after login
return是关键字,不是表达式,必须出现在函数里面啊大哥 js小白试着答一下,欢迎指正。
错误原因是:当在非函数语句中执行"return"语句时,会被js认为是非法语句
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

What do src and href mean? What do src and href mean? Aug 16, 2023 pm 05:00 PM

src and href are respectively, 1. src is the abbreviation of source, which is used to specify the path of external resources. It is usually used to embed external files, such as pictures, audios, videos, etc. The src attribute is generally used on img, script, iframe and other tags. ; 2. href is the abbreviation of hypertext reference, which is used to specify the path of the target resource of the hyperlink. It is usually used to link to external documents or other pages. The href attribute is generally used on tags such as a and link.

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

How to solve Python error: SyntaxError: invalid syntax How to solve Python error: SyntaxError: invalid syntax Aug 17, 2023 pm 07:36 PM

How to solve Python error: SyntaxError: invalidsyntax In the process of programming in Python, you often encounter various errors. Among them, "SyntaxError: invalid syntax" is a common error. It usually indicates the occurrence of a code that does not conform to Python syntax rules. This article will introduce some common causes of "SyntaxError: inv

How to solve 'SyntaxError: Unexpected token' in Vue application? How to solve 'SyntaxError: Unexpected token' in Vue application? Jun 24, 2023 pm 06:55 PM

How to solve "SyntaxError:Unexpectedtoken" in Vue application? Vue is a JavaScript framework widely used in front-end development. It allows us to more easily manage the state, rendering and interaction of the page. However, when writing Vue applications, sometimes you will encounter the "SyntaxError: Unexpectedtoken" error. This error message means that there is a syntax error in the code. The JavaScript engine

Solution to syntaxerror when running Python Solution to syntaxerror when running Python Dec 04, 2023 pm 01:44 PM

Solution to syntaxerror when running Python: 1. Check the code syntax; 2. Use the help of the IDE or code editor; 3. Check the error message; 4. Use Python's compile() function; 5. Make sure to use the correct Python version; 6 , Consider using static code analysis tools; 7. View documentation; 8. Use a debugger; 9. Rewrite or simplify the code; 10. Consider using type annotations; 11. Check third-party libraries or dependencies; 12. Ensure that environment variables are set correctly etc.

What are the differences in functions and usage between the src attribute and the href attribute? What are the differences in functions and usage between the src attribute and the href attribute? Dec 28, 2023 am 08:20 AM

The src attribute and href attribute are commonly used attributes in HTML and are used to load external resources. Although they have similar purposes, there are some differences in usage and purpose. src attribute: The src attribute is used to specify external resources to be embedded in the document. It is mainly used to introduce external script files and media files into HTML documents. It can be used in the following situations: Introduce external JavaScript files: Link external JavaScript files to HTML pages through the src attribute.

Detailed explanation of JavaScript function return values ​​and return statements Detailed explanation of JavaScript function return values ​​and return statements Aug 04, 2022 am 09:46 AM

JavaScript functions provide two interfaces to interact with the outside world. The parameters serve as the entrance to receive external information; the return value serves as the outlet to feed back the operation results to the outside world. The following article will take you to understand the JavaScript function return value and briefly analyze the usage of the return statement. I hope it will be helpful to you!

See all articles