JavaScript onclick passes an object parameter (when Easyui passes a row of data) Error: uncaught syntaxerror:unexpected identifier

Source: Internet
Author: User
Tags object object

JavaScript onclick passes an object parameter (when Easyui passes a row of data) Error: uncaught syntaxerror:unexpected identifier

Bloggers encountered when passing object parameters with the onclick (when Easyui passed a row of data), Sncaught syntaxerror:unexpected identifier error is reported.
It is found that the onclick(对象) object in the form of this transitive object becomes onclick([object Object]) .

    • Workaround: Convert the object to a JSON string, and then translate the double quotation marks of the JSON string into single quotes.
    • Idea: Json.stringify (). replace (/\ "/g," ") transforms the object into a JSON string pass, and the function is automatically transformed into an object after it is received (the principle is not known).
    • Procedure explanation: Json.stringify () converts the object into a JSON string; replace (/\ "/g," ") converts the double quotation marks in the JSON string into single quotes, otherwise it will report an Unexpected end of input error (this error is due to the JSON string that was taken.) Its double quotation marks conflict with the double quotes of the onclick control)

    • Code content is as follows

  • Passing parameters
var $row = JSON.stringify(row).replace(/\"/g,"‘");//row的是一个对象 <a href="#" onclick="editParentRow(‘+$row+‘)">编辑</a>//拼接传递对象
    • 1
    • 2
  • Receive parameters
    function editParentRow(obj){            console.log(obj);//console打印 alert(obj);//提示框 }

JavaScript onclick passes an object parameter (when Easyui passes a row of data) Error: uncaught syntaxerror:unexpected identifier

Related Article

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.