外部JS / jQuery文件正在加载但不能执行 [英] External JS/jQuery files are loading but not executing
本文介绍了外部JS / jQuery文件正在加载但不能执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在chrome开发工具中,下面的所有东西都会被加载。
< head>
<!DOCTYPE html>
< meta charset = utf-8 />
< link rel =stylesheettype =text / csshref =http://fonts.googleapis.com/css?family=Open+Sans>
< script src =http://code.jquery.com/jquery-1.10.1.min.js>< / script>
< script src =http://code.jquery.com/ui/1.10.3/jquery-ui.js>< / script>
< / head>
这是scripts.js文件的一部分:
$(span.output)。draggable({
stop:function(event,ui){}
});
$ b $('input [type = file]')。change(
function(){
$('#submitbutton')。click();
});
$(#text_submit)。submit(
function(event){
$(#text1)。html($(#1)。val ();
$(#text2)。html($(#2)。val());
$(#text3)。html($(#3 ).val());
$(#text4)。html($(#4)。val());
$(#text5)。html (#5)。val());
$(#text6)。html($(#6)。val());
$(#text7) val());
$(#text8)。html($(#8)。val());
$( ($(#9)。val());
$(#text10)。html($(#10)。val()); $ b $显示(); $ b $(#slider2)。show();
$(#slider3)。show();
$ ()#$ b $(#slider7)。show ();
$(#slider9)。show();
event.preventDefault();
});
解决方案
您需要将脚本放在script.js中JQuery的Dom Ready函数,就像这样;
$ $ $ $ $ $ $ document $。$($)$代码
});
欲了解更多信息, http://api.jquery.com/ready/
I am loading all of the below libraries and files, but for some reasons only the CSS is executing and none of the external js files. The scripts.js file holds all of my jQuery and it seems to be formatted properly. I'm not sure why the CSS would execute, but not the jQuery.
In chrome dev tools, everything below is loaded.
<head>
<!DOCTYPE html>
<meta charset=utf-8 />
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/spectrum.css') }}">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='scripts/spectrum.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='scripts/scripts.js') }}"></script>
</head>
This is a portion of the scripts.js file:
$("span.output").draggable({
stop: function(event, ui) {}
});
$('input[type=file]').change(
function() {
$('#submitbutton').click();
});
$("#text_submit").submit(
function(event) {
$("#text1").html($("#1").val());
$("#text2").html($("#2").val());
$("#text3").html($("#3").val());
$("#text4").html($("#4").val());
$("#text5").html($("#5").val());
$("#text6").html($("#6").val());
$("#text7").html($("#7").val());
$("#text8").html($("#8").val());
$("#text9").html($("#9").val());
$("#text10").html($("#10").val());
$("#slider1").show();
$("#slider2").show();
$("#slider3").show();
$("#slider4").show();
$("#slider6").show();
$("#slider7").show();
$("#slider8").show();
$("#slider9").show();
event.preventDefault();
});
解决方案
You need to put your code inside script.js in JQuery's Dom Ready function, like this;
$(document).ready(function(){
// Your code here
});
For more info, http://api.jquery.com/ready/
这篇关于外部JS / jQuery文件正在加载但不能执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文