简体   繁体   English

根据PHP变量的值调用JavaScript函数

[英]Call a JavaScript function depending on the value of a PHP variable

I am passing a variable via the URL as var=5 to urlrun.php (like urlrun.php?var=5 ). 我通过URL将变量var=5传递给urlrun.php (如urlrun.php?var=5 )。 There is a JavaScript function called testrun in urlrun.php . 有一个叫JavaScript函数testrunurlrun.php

Is there a way to call that JavaScript function depending on the value of that variable ( var ) passed through the URL? 有没有一种方法可以根据通过URL传递的变量( var )的值来调用该JavaScript函数?

For example, if($_GET['var']==5) , I need to call that JavaScript function. 例如, if($_GET['var']==5) ,我需要调用该JavaScript函数。

Put this somewhere: 将此放在某处:

<?php if($_GET['var'] == 5) { ?>
    <script type="text/javascript">
        testrun();
    </script>
<?php } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM