我有一个 php 变量,需要将其传递到 javascript 函数中的链接
//In the config
<?php
define('THE_VAR', 'test');
?>
//On the page
<?php
$the_var = THE_VAR;
?>
<script>
(function()){
link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"
})();
</script>
我需要 javascript 函数中的链接来读取。
test.site/test/testing.js
最佳答案
而不是:link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"
使用:link = "test.site/<?= $the_var; ?>/testing.js";
关于javascript - 在javascript变量中添加php定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29167096/