【问题标题】:jQuery not working in djangojQuery 在 Django 中不起作用
【发布时间】:2012-04-04 04:08:52
【问题描述】:

我正在尝试使用

在页面上打印 html 数据 result
$("#regerror").html(result);

这是行不通的。但是使用普通的 javascript 是可行的

document.getElementById("regerror").innerHTML = result;

我使用 Django。这就是我将库包含在基本模板中的方式。

<script type="text/javascript" src="{{ MEDIA_URL }}jquery/js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}base.js"></script>

【问题讨论】:

  • 你有jquery加载到页面吗?
  • 你的head标签中是否包含了jQuery库?
  • 页面上有jquery吗?好像你没有。 javascript 控制台中是否有任何错误?
  • 更多信息... 什么样的元素?结果是什么?你能在jsfiddle中提供一个工作示例吗?
  • 我的 javascript 代码在 base.js 文件中

标签: javascript jquery django


【解决方案1】:

您很可能忘记或错误链接了 JQuery 库,或者您在加载库之前调用它。

Here's a standalone 向您展示它确实有效。

这是当前版本

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>

这是一个简单的例子

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script>
$(document).ready(function(){
    $.ajax({
        url: "whatever.html",
        success: function(result){
            $("#results").html(result);
        }
    });
});
</script>

<div id="results"></div>

RTFM...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2014-01-08
    • 2015-09-19
    • 2012-12-29
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多