jQuery .load()但排除脚本标记 [英] jQuery .load() but exclude script tags
本文介绍了jQuery .load()但排除脚本标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下jQuery将5页加载到当前页面中
I am using the following jQuery to load in 5 pages into the current page
$('.main').load('main.cfm');
$('.bu1').load('bu1.cfm');
$('.bu2').load('bu2.cfm');
$('.bu3').load('bu3.cfm');
$('.bu4').load('bu4.cfm');
但每个 .cfm
具有以下 script
其中的标签
But each .cfm
has the following script
tags in them
<script src="js/jquery.speedometer.js"></script>
<script src="js/jquery.jqcanvas-modified.js"></script>
<script src="js//excanvas-modified.js"></script>
<script>
$(function(){
$('#MDTQ').speedometer({
backgroundImage: "url(speedo/background-r.png)",
maximum: 15,
scale: 15,
suffix: ''
});
$('.changeSpeedometer').click(function(){
$('#MDTQ').speedometer({ percentage: $('.speedometer').val() || 0 });
});
});
</script>
有没有办法在加载时从下面的页面中删除下面的内容?
Is there a way to remove the below from the pages below whilst being loaded?
$('.bu1').load('bu1.cfm');
$('.bu2').load('bu2.cfm');
$('.bu3').load('bu3.cfm');
$('.bu4').load('bu4.cfm');
谢谢
推荐答案
由于load是$ .get的快捷方式,可以方便地为您自动插入内容,您可以使用它并在自己插入内容之前过滤掉脚本标记:
As load is a shortcut for $.get with the convenience of automagically inserting the content for you, you can use that and filter out the script tags before inserting the content yourself:
$.get('bu1.cfm', function(html) {
var markup = $($.trim(html));
markup.find('script').remove();
$('.bu1').html(markup);
});
编辑:
按src过滤:
$.get('bu1.cfm', function(html) {
var markup = $($.trim(html));
$('script[src]', markup).remove();
$('.bu1').html(markup);
});
这篇关于jQuery .load()但排除脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文