JavaScript-Deploy to the line of the project, write in the JS file need to dynamically load the picture path how to find?

Source: Internet
Author: User
img/grades.png" alt="分数"/>

In the homepage through such a way to get the path of static resources, but in the JS file I need to go to the dynamic addition of some pictures will not show, JS can not write PHP statements, how can I find it?
For example, if you want to click on this image and replace it with another picture, this click event I wrote in a separate JS file, in the JS file how to get the image to replace it?

$('.share-dream').click(function(){        $(".share-dream").attr(        "src",        "
  
   img/shareBtnClick.png")    })//我可以这么写么

Reply content:

img/grades.png" alt="分数"/>

In the homepage through such a way to get the path of static resources, but in the JS file I need to go to the dynamic addition of some pictures will not show, JS can not write PHP statements, how can I find it?
For example, if you want to click on this image and replace it with another picture, this click event I wrote in a separate JS file, in the JS file how to get the image to replace it?

$('.share-dream').click(function(){        $(".share-dream").attr(        "src",        "
  
   img/shareBtnClick.png")    })//我可以这么写么

How could the introduction of JS file execute PHP code
I usually put a hidden field in the template HTML that introduced the JS file, such as

The JS file is then implemented dynamically by acquiring the value of this hidden field

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

Then the question comes, who said JS inside can not write PHP?

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

This typically requires a backend to be configured in JS (back-end template).
Like what:

javascriptvar ACTION_SET = {   host:''}

Then the front-end call can be.

JS want to write PHP to write JS directly in the PHP page

In general, if it is public data, it is configured in a public template

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