判断一个页面是否加载了某个js文件
2017-01-26 12:11
1096 查看
在加载嵌套等页面的时候,遇见了一种这样的情况,有的文件中已经加载了某个js,但是又加载了一遍,导致有些插件不能正常使用。
例如:
<!-- 这种是判断某个js文件是否加载 -->
<script>!window.jQuery && document.write('<script src="public/js/jquery-1.11.1.min.js"><\/script>');</script>
<!-- 这种是判断某个js文件是否加载 -->
Highchart不能重复加载,放别的页面重复load时,需要重置它
<script>
if (window.Highcharts) {
window.Highcharts = null;
window.HighchartsAdapter = null;
}
</script>
<script type="text/javascript" src="public/js/highchart/highcharts.js"></script>
<script type="text/javascript" src="public/js/highchart/exporting.js"></script>
<script type="text/javascript" src="public/js/hScroll/hScrollPane.js" ></script>
<script type="text/javascript" src="public/js/hScroll/jquery.mousewheel.js" ></script>
<link href="public/js/hScroll/hScrollPane.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
var chart = null;
<!--{if $ulist_json}-->
charts.ChartObj = {$ulist_json};
charts.ChartDiv = 'container';
charts.EvalInit();
chart = new Highcharts.Chart(EvalChart);
$(".chart").hScrollPane({
mover:"#container", //指定container对象下的哪个元素需要滚动位置 | 必传项;
showArrow:false, //指定是否显示左右箭头,默认不显示 | 可选项;
//moverW:function(){return $(".press").width();}(), //传入水平滚动对象的长度值,不传入的话默认直接获取mover的宽度值 | 可选项;
handleMinWidth:50,//指定handle的最小宽度,要固定handle的宽度请在css中设定handle的width属性(如 width:28px!important;),不传入则不设定最小宽度 | 可选项;
//dragable:true, //指定是否要支持拖动效果,默认可以拖动 | 可选项;
//easing:true, //滚动是否需要滑动效果,默认有滑动效果 | 可选项;
//handleCssAlter:"draghandlealter", //指定拖动鼠标时滚动条的样式,不传入该参数则没有变化效果 | 可选项;
mousewheel:{moveLength:200} //mousewheel: bind->'true',绑定mousewheel事件; ->'false',不绑定mousewheel事件;moveLength是指定鼠标滚动一次移动的距离,默认值:{bind:true,moveLength:300} | 可选项;
});
<!--{else}-->
$('#content').html('没有查询到记录');
<!--{/if}-->
});
</script>
<div id="content" style="text-align:center; margin:auto;">
<div class="chart" style="height:520px;overflow:hidden;position:relative;">
<div id="container" style="white-space:nowrap;position:absolute;"></div>
</div>
</div>
例如:
<!-- 这种是判断某个js文件是否加载 -->
<script>!window.jQuery && document.write('<script src="public/js/jquery-1.11.1.min.js"><\/script>');</script>
<!-- 这种是判断某个js文件是否加载 -->
Highchart不能重复加载,放别的页面重复load时,需要重置它
<script>
if (window.Highcharts) {
window.Highcharts = null;
window.HighchartsAdapter = null;
}
</script>
<script type="text/javascript" src="public/js/highchart/highcharts.js"></script>
<script type="text/javascript" src="public/js/highchart/exporting.js"></script>
<script type="text/javascript" src="public/js/hScroll/hScrollPane.js" ></script>
<script type="text/javascript" src="public/js/hScroll/jquery.mousewheel.js" ></script>
<link href="public/js/hScroll/hScrollPane.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
var chart = null;
<!--{if $ulist_json}-->
charts.ChartObj = {$ulist_json};
charts.ChartDiv = 'container';
charts.EvalInit();
chart = new Highcharts.Chart(EvalChart);
$(".chart").hScrollPane({
mover:"#container", //指定container对象下的哪个元素需要滚动位置 | 必传项;
showArrow:false, //指定是否显示左右箭头,默认不显示 | 可选项;
//moverW:function(){return $(".press").width();}(), //传入水平滚动对象的长度值,不传入的话默认直接获取mover的宽度值 | 可选项;
handleMinWidth:50,//指定handle的最小宽度,要固定handle的宽度请在css中设定handle的width属性(如 width:28px!important;),不传入则不设定最小宽度 | 可选项;
//dragable:true, //指定是否要支持拖动效果,默认可以拖动 | 可选项;
//easing:true, //滚动是否需要滑动效果,默认有滑动效果 | 可选项;
//handleCssAlter:"draghandlealter", //指定拖动鼠标时滚动条的样式,不传入该参数则没有变化效果 | 可选项;
mousewheel:{moveLength:200} //mousewheel: bind->'true',绑定mousewheel事件; ->'false',不绑定mousewheel事件;moveLength是指定鼠标滚动一次移动的距离,默认值:{bind:true,moveLength:300} | 可选项;
});
<!--{else}-->
$('#content').html('没有查询到记录');
<!--{/if}-->
});
</script>
<div id="content" style="text-align:center; margin:auto;">
<div class="chart" style="height:520px;overflow:hidden;position:relative;">
<div id="container" style="white-space:nowrap;position:absolute;"></div>
</div>
</div>
相关文章推荐
- 在JS文件中对同一个页面是否存在另一个js进行判断
- 在css加载完毕后自动判断页面是否加入css或js文件
- 在css加载完毕后自动判断页面是否加入css或js文件
- js判断页面是否加载完毕
- js判断页面是否加载完毕
- JS如何判断一个页面是否已经打开?
- Delphi中WebBrowser判断页面及JS是否加载完成
- js中常用方法以及document.readyState 判断页面是否加载完成 complete和interactive
- 每日总结:每个 GROUP BY 表达式必须至少包含一个不是外部引用的列、加载页面时调用Js方法、调用Js文件中的方法
- magento的robots文件编写和判断是否是一个导航分类页面
- js判断页面嵌套的iframe是否加载完成
- js 页面加载完成后判断表单元素是否存在
- js判断页面是否加载完毕
- 向页面动态加载JS文件的的一个小技巧
- 用js判断页面是否加载完成实现代码
- 页面加载时判断是否登陆(js)
- Delphi中WebBrowser判断页面及JS是否加载完成
- 用js判断页面是否加载完成
- JS判断页面是否加载完成 readyState
- JS判断页面是否加载完成