Sharing a JS file nested PHP will be an error problem

Source: Internet
Author: User
Premise:

Use thinkphp. The background passes a variable to the HTML page: $this->assign ("variable", $variable);

Problem:

In the HTML page nested JS code, in the JS code to output this variable:

 


The above code is migrated to the JS file Variable.js, and then in the HTML page introduced this JS file, this time will be wrong, not only output does not come, or cause JS error, JS code can not run.

My workaround is to:

  1. Write Hidden tags

    Then get the value of the element in JS

  2. If you are using JQ, you can add attributes to the tag:

    I'm the Div.

Js:var variable =$ ("div"). attr ("Data-value");

Both of the above methods have a flaw, that is, Variabe are visible, as long as others "review elements" can see your variable is what, is confidential data is not recommended to do so.

  • 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.