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:
javascript
var 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