Django jquery不起作用 [英] Django jquery does not work

查看:593
本文介绍了Django jquery不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能运行jQuery操作。我也尝试过其他功能,但没有。我想是一直处理静态文件的问题。



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>


  1. 进入Django项目中的settings.py文件。检查您的 STATIC_URL 前缀是否设置为 / static / ,而 STATIC_ROOT ='' / code>


  2. 验证机器上的路径是否存在 /static/js/jquery.js


  3. 打开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:

  1. Go into your settings.py file in the Django project. Check that your STATIC_URL prefix is set to /static/ and that STATIC_ROOT = ''

  2. Verify that the path on your machine exists for /static/js/jquery.js

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆