有没有办法停止' <script>'从加载相同的javascript两次在PHP/ javascript /HT

Is there a way to stop `<script>' from loading the same javascript twice in PHP/Javascript/HTML?

本文关键字:javascript HT 两次 PHP 加载 script 有没有      更新时间:2023-09-26

是否有一个PHP require_onceinclude_once<script> ?我知道<script>是纯HTML,但PHP或HTML有这样的事情吗?

我想防止javascript在同一页面中加载两次。

的例子:

    <script type="text/javascript" src="js/jquery-0.4.ajaxify.min.js"></script> 

似乎你正在寻找这个:

http://wonko.com/post/painless_javascript_lazy_loading_with_lazyload

在php中运行脚本标签的一种方式是

<?php  
....Here is php code
 ?>
   ... add the  script here(<script>....</script>
 <?php
  ?>

另一种可能的方式是:

在脚本标签中使用php,例如:

<script type="text/javascript">
  var alertMsg = '<?php echo $custom_message; ?>';  
   alert(alertMsg);
 </script>

如果使用按钮

echo('<button type="button" onclick="customfunction();">My Button</button>');
<script>
//call your customfunction here
</script>

解决两次加载脚本内容的更新

我建议使用javascript函数调用到特定的页面,因为他们需要一个例子将是

创建一个.js文件,例如

example.js
here declare your functions you would put in the script tags of a html page

在你想使用<script>

的页面
Include the example.js file and you can call the custom functions from there use the obect orientend approach

查看此资源获取更多关于面向对象javascript的信息

相关文章: