Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery在ajax调用后不工作,即使我';我正在使用正确的on()方法_Javascript_Jquery_Ajax_Django_Pagination - Fatal编程技术网

Javascript jQuery在ajax调用后不工作,即使我';我正在使用正确的on()方法

Javascript jQuery在ajax调用后不工作,即使我';我正在使用正确的on()方法,javascript,jquery,ajax,django,pagination,Javascript,Jquery,Ajax,Django,Pagination,我使用的是django el分页,一个。我正在为注释(注释列表)的查询集分页。查询集位于comments.html内,它位于comments\u base.html内,它位于article.html内(父视图)。以下是我的看法: def article(request, category, id, extra_context=None): name = resolve(request.path).kwargs['category'] instance = get_object_o

我使用的是
django el分页
,一个。我正在为
注释
(注释列表)的查询集分页。查询集位于
comments.html
内,它位于
comments\u base.html
内,它位于
article.html
内(父视图)。以下是我的看法:

def article(request, category, id, extra_context=None):
    name = resolve(request.path).kwargs['category']
    instance = get_object_or_404(Post, id=id, entered_category=name)

    new_comments_list = Comment.objects.filter(destination=id, parent_id=0).order_by('-timestamp')

    template = 'article.html'
    page_template = 'comments.html'

    if request.is_ajax():
        template = page_template

    context = {
        'id': id,
        'comment_list': new_comments_list,
        'page_template': page_template,
        'instance': instance,
    }
    if extra_context is not None:
        context.update(extra_context)
    return render(request, template, context)
评论\u base.html

{% block comments_base %}

<div class="commentsContainer">
    <div class="endless_page_template">
        {% include 'comments.html' %}
    </div>
    {% block js %}
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="{% static 'js/el-pagination/js/el-pagination.js' %}"></script>
        <script>
        $.endlessPaginate({
        });
        </script>
    {% endblock %}
</div>

{% endblock %}
{% block comments %}

{% paginate 10 comment_list %}
    {% for i in comment_list %}
        {% if i.parent_comment %}
            <div class="comment_shell hasParent">
         {% else %}
            <div>
        {% endif %}
        <div class='comment_div' data-comment_id="{{ i.id }}">
            <div class="left_comment_div">
                <div class="username_and_votes">
                    <h3><a class='username_foreign'>{{ i.user }}</a></h3>
                    {% for j in i.score.all %}
                        <span class="upvotes">{{ j.upvotes }}</span>
                        <span class="downvotes">{{ j.downvotes }}</span>
                    {% endfor %}
                </div>
                <br>
                <p>{{ i.comment_text }}</p>
            </div>
        </div>
        {% include 'comments.html' with comment_list=i.replies.all %}
    </div>

    {% endfor %}
{% show_pages %}


{% endblock %}

单击后不会改变颜色。那么,有什么原因导致它仍然不能工作,我如何修复它呢?

这听起来像是jquery的
on
方法重载的一个应用程序,它使用了额外的选择器参数:

.on(事件[,选择器][,数据],处理程序)

从jquery文档中:

当提供选择器时,事件处理程序称为委派。当事件直接发生在绑定元素上时,不会调用该处理程序,而仅针对与选择器匹配的子体(内部元素)

因此,这应该是可行的:

$('body').on('click', '.upvotes', function() {
    $(this).css('color', '#fff'); 
});

或者使用执行javascript时DOM中存在的任何其他元素来代替“body”选择器。

为什么要使用jquery。改用
(单击)
。我已经试过了,但没用。另外,每个其他答案都说在()上使用
:编辑:单击是指
$('.upvotes')。单击(函数()
?您试图实现的是什么?告诉我我将帮助您选择或修复此问题。jQuery在附加(动态)上不起作用所以jQuery不能在第一个注释集之后对我分页的每个注释集都起作用。
$('body').on('click', '.upvotes', function() {
    $(this).css('color', '#fff'); 
});