【问题标题】:How to add an onChange event to Django form fields with field itself as an argument如何以字段本身作为参数向 Django 表单字段添加 onChange 事件
【发布时间】:2014-06-18 09:11:40
【问题描述】:

我在 TextField 上动态添加 onChange 事件。以下代码解释了我在做什么:

fields.widget.attrs['onchange'] = 'execute_function(arg)'

我已将字段本身添加为 javascript 函数的参数,类似于 django 表单中的function_name(this)。

我想将字段本身作为函数的参数传递给 execute_function()。

【问题讨论】:

    标签: javascript python-2.7 django-forms


    【解决方案1】:

    如果我理解你的问题,应该就像将 arg 更改为 this 一样简单:

    fields.widget.attrs['onchange'] = 'execute_function(this)'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多