Javascript-How do I find the image paths that need to be dynamically loaded in js files for projects deployed online?

Source: Internet
Author: User
{Code ...} on the homepage, you can use this method to obtain the path of static resources. However, some images that need to be dynamically added in js files are not displayed, and php statements cannot be written in js, how can I find it? For example, if you want to click this image and change it to another image, this click event I...
Img/grades.png "alt =" score "/>

On the homepage, you can use this method to obtain the path of static resources. However, some images that need to be dynamically added in js files are not displayed, and php statements cannot be written in js, how can I find it?
For example, if you want to click this image and change it to another image, I will write this click event in a separate js file. How can you get the image to be replaced in the js file?

$ ('. Share-dream'). click (function () {$ (". share-dream"). attr ("src ","
  Img/shareBtnClick.png ")}) // can I write this statement?

Reply content:
Img/grades.png "alt =" score "/>

On the homepage, you can use this method to obtain the path of static resources. However, some images that need to be dynamically added in js files are not displayed, and php statements cannot be written in js, how can I find it?
For example, if you want to click this image and change it to another image, I will write this click event in a separate js file. How can you get the image to be replaced in the js file?

$ ('. Share-dream'). click (function () {$ (". share-dream"). attr ("src ","
  Img/shareBtnClick.png ")}) // can I write this statement?

How can I introduce JavaScript files to execute PHP code?
I usually put hidden fields in the HTML template that introduced JS files, such

Then, the js file obtains the value of this hidden field to achieve dynamic

$('.share-dream').click(function(){        $(".share-dream").attr(        "src",$('#thisActAssetsRoot').val()+"img/shareBtnClick.png")    })

So the question is, who said that PHP cannot be written in JS?

function assest(url) { return "
  "+url; }console.log( assest("img/grades.png") );

This usually requires backend configuration in js (backend template ).
For example:

javascriptvar ACTION_SET = {   host:''}

Then the frontend can call.

To write php in js, you need to write js directly on the php page.

Generally, public data is configured in the public template.

javascript《script》    var cVar = {        "SITE_URL": "
  ",        "IMG_DOMAIN": "
  "    };《script》

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.