即使没有单击按钮,也会触发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:通过自定义模板标签用户输入修改数据?(Django: modifying data with user input through custom template tag?)[2023-01-11]
此类逻辑不属于模板标记。 它属于一个视图,它将响应AJAX请求并返回JSONResponse。 你需要一些javascript来处理基于输入的请求。 This type of logic does not belong in a template tag. It belongs in a view that will respond to AJAX requests and return a JSONResponse. You'll need some javascript to handle making ... -
这是我的解决方案(基于自定义标签 ): 首先创建文件结构。 进入需要标签的应用程序目录,并添加以下文件: templatetags templatetags/__init__.py templatetags/video_tags.py templateatetags / video_tags.py文件: from django import template register = template.Library() @register.simple_tag def get_rate(crit, ra ...
-
您可以将takes_context参数用于装饰器。 @register.simple_tag(takes_context=True) def sampletag(context): return context['templatevar'] 请参阅模板标签文档 。 You can use the takes_context parameter to the decorator. @register.simple_tag(takes_context=True) def sampletag(conte ...
-
简单的url标签支持分配。 {% url 'myview' as my_url %} {% my_tag arg1 my_url arg3=5 %} Simple url tag supports assignment. {% url 'myview' as my_url %} {% my_tag arg1 my_url arg3=5 %}
-
Django - 创建自定义标记以通过模板中的索引访问变量(Django - create custom tag to acces variable by index in template)[2022-02-01]
如果您不想要2条线,那么您应该能够使用过滤器 @register.filter def list_index(a, b): return a[b] 然后用这样的用法 {% for contestant in contestants_dict|list_index:category.id %} {{ contestant }} {% endfor %} If you don't want 2 lines like that you should be able to use a ... -
我相信你可以使用 {% for object in object_list %}
- {{object.name}}
{% endfor %} 并完全删除{% url %}的使用。 根据文档,为您的模型定义方法get_absolute_url是解决问题的推荐方法。 I believe you can use {% for object in object_list %}不, 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': ...相关文章
更多- storm事件管理器EventManager源码分析-event.clj
- 用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空
- 微信公众号接口添加菜单时错误(errcode":40017 invalid button type)
- Solr参数(DisMax Event Facet)
- 解决点击没有内容的空白div没有响应click事件的方法
- JavaScript 事件
- JavaScript 事件
- (转)C# .net微信开发,开发认证,关注触发消息,自动应答,事件响应,自定义菜单
- C# .net微信开发,开发认证,关注触发消息,自动应答,事件响应,自定义菜单
- 微信公众平台自定义菜单接口API指南
最新问答
更多- 获取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的基本操作命令。。。