首页 \ 问答 \ 即使没有单击按钮,也会触发click事件(click event fired even if the button has not been clicked)

即使没有单击按钮,也会触发click事件(click event fired even if the button has not been clicked)

我想使用jquery将函数绑定到按钮。 但是当页面加载而不是单击按钮时会触发该事件。 这是代码:

$(document).ready(function(){

    function getStudents(view) {

    /* do something */
    }
    $('#buttonAB').click(getStudents("corsoAB"));

});

我错了什么?


I want bind a function to a button using jquery. But the event is fired when the page is load instead of when the button is clicked. this is the code:

$(document).ready(function(){

    function getStudents(view) {

    /* do something */
    }
    $('#buttonAB').click(getStudents("corsoAB"));

});

what I'm wrong?


原文:https://stackoverflow.com/questions/19766465
更新时间:2022-03-03 16:03

最满意答案

您不能将templatetag用作变量,因此:

{% for num in random_num  %}

无法工作。

您需要将您的模板标签更改为分配标签

@register.assignment_tag
def random_num():
    numbers = range(1,18)
    shuffle(numbers)
    return numbers

...并使用模板中的as子句:

{% random_num as numlist %}
{% for num in numlist  %}
    {{ num }}
{% endfor %}

You cannot use the templatetag as a variable, so:

{% for num in random_num  %}

can't work.

You need to change your templatetag to an assignment tag

@register.assignment_tag
def random_num():
    numbers = range(1,18)
    shuffle(numbers)
    return numbers

...and use the as clause in the template:

{% random_num as numlist %}
{% for num in numlist  %}
    {{ num }}
{% endfor %}

相关问答

更多
  • 不, django.template.loaders.app_directories.load_template_source完全不需要自定义模板标签正常工作。 您不必指定目录来告诉django从哪里加载模板标签库(就像模板一样),只需要coz django假定在INSTALLED_APPS列表中指定的应用程序中找到模板标签库。 它只是遍布INSTALLED_APPS的应用程序列表,从“ templatetags ”目录中导入所有库,并导入每个库以使其可用。 如果找不到名为templatetags的目录,它 ...
  • 您不能将templatetag用作变量,因此: {% for num in random_num %} 无法工作。 您需要将您的模板标签更改为分配标签 @register.assignment_tag def random_num(): numbers = range(1,18) shuffle(numbers) return numbers ...并使用模板中的as子句: {% random_num as numlist %} {% for num in numlist % ...
  • 我不确定你需要完成什么,或者你的方法确实是最好的方法,但是我建议你在这forloop.first之前先看看forloop.first变量。 你的方法一眼就看起来很尴尬,但我可能错了,因为我不知道具体情况 django用于模板标签 很可能你应该能够根据自己的需要进行这项工作,但是如果它不足,我会建议for for template标签的源代码(以及它的forloop变量)可能非常具体说明你如何实现你的''重新做。 I'm not exactly sure what you need to accomplish ...
  • 您正在使用is关键字, 它检查对象标识匹配 ,因此始终失败。 而是使用==来检查相等性,并执行: @register.filter(name='replace_date_separator') def replace_date_separator(value, arg): if arg == 'fr-CA': return value.replace("/", '-') elif arg == 'de' or arg == 'pl' or arg == 'ru': ...
  • 相关文章

    更多

    最新问答

    更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。