[英]external js not loading
I'm trying to get this codepen code working locally: 我正在尝试使此Codepen代码在本地工作:
http://codepen.io/desandro/pen/mCdbD/ http://codepen.io/desandro/pen/mCdbD/
However, when I try to load the js as an external script, it does not work: 但是,当我尝试将js作为外部脚本加载时,它不起作用:
<!DOCTYPE html>
<html lang = "en">
<script src="isotope.pkgd.js"></script>
<script src="jquery.min.js"></script>
<script src="isotopes.js"></script>
But if I copy paste the file into the markup: 但是,如果我复制将文件粘贴到标记中:
<!DOCTYPE html>
<html lang = "en">
<script src="jquery.min.js"></script>
<script src="isotope.pkgd.js"></script>
<script>
$( function() {
// quick search regex
var qsRegex;
var buttonFilter;
// init Isotope
var $container = $('.isotope').isotope({
itemSelector: '.element-item',
layoutMode: 'fitRows',
filter: function() {
var $this = $(this);
var searchResult = qsRegex ? $this.text().match( qsRegex ) : true;
var buttonResult = buttonFilter ? $this.is( buttonFilter ) : true;
return searchResult && buttonResult;
}
});
$('#filters').on( 'click', 'button', function() {
buttonFilter = $( this ).attr('data-filter');
$container.isotope();
});
// use value of search field to filter
var $quicksearch = $('#quicksearch').keyup( debounce( function() {
qsRegex = new RegExp( $quicksearch.val(), 'gi' );
$container.isotope();
}) );
// change is-checked class on buttons
$('.button-group').each( function( i, buttonGroup ) {
var $buttonGroup = $( buttonGroup );
$buttonGroup.on( 'click', 'button', function() {
$buttonGroup.find('.is-checked').removeClass('is-checked');
$( this ).addClass('is-checked');
});
});
});
// debounce so filtering doesn't happen every millisecond
function debounce( fn, threshold ) {
var timeout;
return function debounced() {
if ( timeout ) {
clearTimeout( timeout );
}
function delayed() {
fn();
timeout = null;
}
setTimeout( delayed, threshold || 100 );
};
}
</script>
<link rel = "stylesheet" type= "text/css" href = "style.css">
<h1>Isotope - filtering with search field and button filters</h1>...
Then it does work sometimes. 然后有时它确实起作用。 Could someone explain how to get the external js file loading? 有人可以解释如何获取外部js文件吗?
HTML 4.01中必须提供type属性(来源: http : //www.w3schools.com/tags/tag_script.asp )。
<script type="text/javascript" src="file.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.