How do you call a JavaScript function from one PHP file that is defined in another PHP file?

如何从另一个PHP文件中定义的一个PHP文件中调用JavaScript函数?

3 个解决方案

#1


This is a best guess at what you want :)

这是你想要的最佳猜测:)

I am assuming you have two php files, that end up being sent to the browser as html. The solution is to move your javascript function to an separate (external) javascript file and include them in both of the php files (not with the phps include. See below). That way you can call the javascript function from both files.

我假设你有两个php文件,最终以html的形式发送到浏览器。解决方案是将你的javascript函数移动到一个单独的(外部)javascript文件,并将它们包含在两个php文件中(不包括phps include。见下文)。这样你就可以从两个文件中调用javascript函数。

All you need to do is move the function to an new file, then put the link to the external javascript file in the head of the html code (in the php file)

你需要做的就是将函数移动到一个新文件,然后将链接放到html代码头部的外部javascript文件中(在php文件中)

<script type="text/javascript" src="js_src.js"></script>

更多相关文章

  1. python (9)统计文件夹下的所有文件夹数目、统计文件夹下所有文件数
  2. Python 内置函数及excel操作
  3. Python3 函数式编程(高阶函数)
  4. python中range()函数的用法--转载
  5. Python3入门(六)——函数式编程
  6. 使用Python写HTML 文件使用jinja2中的模板
  7. Python执行系统命令:使用subprocess的Popen函数
  8. python传递列表作为函数参数
  9. Python读取修改ini配置文件[ConfigParser]

随机推荐

  1. php实现性能优化
  2. 关于php中变量的初始化以及赋值方式的介
  3. 通过header函数设置响应头解决php跨域问
  4. PHP安装BCMath扩展
  5. 浅析PHP类的自动加载和命名空间
  6. 关于在php中使用curl发送get请求时参数传
  7. 基于AIML的PHP聊天机器人
  8. PHP多任务秒级定时器的实现方法
  9. 四种好用的PHP自定义加密函数(可逆/不可逆
  10. php实现上传图片功能