有没有办法停止' <script>'从加载相同的javascript两次在PHP/ javascript /HT
Is there a way to stop `<script>' from loading the same javascript twice in PHP/Javascript/HTML?
是否有一个PHP require_once
或include_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的信息
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 使用php或javascript从facebook相册URL中删除多余的部分
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在JavaScript中将字符串转换为函数引用
- 模糊事件的Javascript测试
- Javascript更改图标
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何使用WCF服务和javascript表单post上传.doc文件
- javascript结合了数组和字典
- 这是什么 ==- javascript 运算符
- 从javascript创建一个列表
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 在 Google App Engine 中使用 JavaScript 和服务器端 Python 代码动态生成客户端 HT
- 如果我使用 jQuery 的 .hide() 和 .show() 方法,如何将 javascript 验证仅应用于 HT
- 有没有办法停止'