Uncaught syntaxerror:unexpected token illegal JS pass parameters with spaces

Source: Internet
Author: User

The onclick is usually used to generate click events (non-page jumps) on the page to make certain content clickable, but this is not suitable for situations where parameters need to be passed, so it is written as a direct call to the JavaScript function: <a href=javascript: Somefunction (args) >content</a>. Note that this is problematic, the problem is that the somefunction parameter args value cannot contain spaces, otherwise the browser will assume that the content after the space is a property of the <a> tag, the correct way to write is to use quotation marks to the javascript: caused by somefunction (args). There is also a way to do not have to add this pair of quotation marks, the possibility of a space with the parameters of the escape function, and then in the somefunction with the Unescape function decoding the line. It is noteworthy that encodeURI, decodeURI and decoding are not successful.

Find the difference between escape and unescape, encodeURI and decodeURI, encodeURIComponent and decodeuricomponent three on the Internet:

Escape does not encode characters with 69: *,+,-,.,/,@,_,0-9,a-z,a-z

encodeURI does not encode 82 characters:!,#,$,&, ', (,), *,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,a-z

encodeURIComponent does not encode 71 characters:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

A simple summary of the usage, when the URL is not passed, that is, pure JavaScript call with Escape, when the URL is involved, the entire URL is usually processed with encodeURI, only if the URL contains special parameters, The encodeuricomponent is used locally for this special parameter.

if (All.aData.photo! = "") {var a = escape (ALL.ADATA.WT); return  "<a  onclick=\" infooperation (' "+a+" ', ' "+ all.adata.thly+ "', '" +all.adata.photo+ "') \" href=\ "#\" title = ' View All ' ><font color=blue> ' + All.aData.wt.substr (0, +) + "</font></a> ";} else{var a = Escape (ALL.ADATA.WT), return  "<a  onclick=\" infooperation (' + + + ', ' "+all.adata.thly+" ', ' "+ all.adata.photo+ "') \" href=\ "#\" title = ' View All ' ><font color=blue> "+ all.aData.wt.substr (0, +) +" </font ></a> ";} function Infooperation (str,thyy,photo) {var url = encodeURI (contextpath+ "/business/question/wtfk/wtfkxq.jsp?str=" + str+ "&thyy=" +thyy+ "&photo=" +photo) Top.opendialog (contextpath+ "/business/question/wtfk/wtfkxq.jsp?str= "+str+" &thyy= "+thyy+" &photo= "+photo,{height:515,width:1100,title:" View Photos "});  

var str =unescape ($ (). Getparmbyurl (' str ')), var thyy = $ (). Getparmbyurl (' thyy '); var photo = $ (). Getparmbyurl (' photo ');

Uncaught syntaxerror:unexpected token illegal JS pass parameters with spaces

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.