Django jquery不起作用 [英] Django jquery does not work
问题描述
notes.html:
code>< div>
< script type =text / javascriptsrc =static / js / jquery.js>< / script>
< script type =text / javascriptsrc =static / js / init.js>< / script>
< h2>< p id =title> < a href =/ notes / get / {{note.id}} /> {{note.title}}< / a>< / p>< / h2>
< p id =body> {{note.body | lower | truncatewords:10}}< / p>
< / div>
init.js
$('#body')。click(function(){
$('#body')。hide();
}) ;
我可以想到几件事要尝试: / p>
-
进入Django项目中的settings.py文件。检查您的
STATIC_URL
前缀是否设置为/ static /
,而STATIC_ROOT ='' / code>
-
验证机器上的路径是否存在
/static/js/jquery.js
-
打开Firebug或Chrome Inspector,确认jQuery正在加载。在Firebug中,这是在Net选项卡下,您应该看到一个GET请求与jquery.js。如果可以看到,那么在Firebug控制台中输入
$。
,它会显示一个jQuery函数列表。
I am not able to run jQuery operations.I also tried other functions but nothing. I guess the problem is in handling static files as always.
notes.html:
<div>
<script type="text/javascript" src="static/js/jquery.js" ></script>
<script type="text/javascript" src="static/js/init.js" ></script>
<h2><p id="title" > <a href="/notes/get/{{ note.id }}/" >{{ note.title }}</a></p></h2>
<p id="body" > {{ note.body|lower|truncatewords:"10"}}</p>
</div>
init.js
$('#body').click(function(){
$('#body').hide();
});
I can think of a few things to try:
Go into your settings.py file in the Django project. Check that your
STATIC_URL
prefix is set to/static/
and thatSTATIC_ROOT = ''
Verify that the path on your machine exists for
/static/js/jquery.js
Open up Firebug or Chrome Inspector and verify that jQuery is loading. In Firebug, this is under the Net tab, and you should see a GET request with jquery.js. If you can see that, then enter
$.
in the Firebug console, which brings up a list of jQuery functions.
这篇关于Django jquery不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!