我有一个生成变量的 php 文件,我希望将该变量放入一个 javascript 函数中,该函数由主页上的 onclick 调用.这可以从 PHP 发送到 javascript 吗?
I have a php file that generates a variable and I would like the variable to be put into a javascript function which is called by onclick on the main page. Is this possible to send from PHP to javascript?
您可以执行以下操作:
<script type='text/javascript'>
document.body.onclick(function(){
var myVariable = <?php echo(json_encode($myVariable)); ?>;
};
</script>
这篇关于将 PHP 变量发送到 javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!