如何将一个onChange事件添加到Django表单字段中,并将字段本身作为参数 [英] How to add an onChange event to Django form fields with field itself as an argument
本文介绍了如何将一个onChange事件添加到Django表单字段中,并将字段本身作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在动态地在TextField上添加 onChange
事件。以下代码解释了我在做什么:
I'm adding onChange
event on a TextField dynamically. The following code explains what I'm doing:
fields.widget.attrs['onchange'] = 'execute_function(arg)'
我已将字段本身添加为javascript函数的参数,类似于 function_name (这)
在django表格中。
I have add field itself as an argument to javascript function similar to function_name(this)
in django forms.
我想将字段本身传递给execute_function()作为函数的参数。
I want to pass the field itself to execute_function() as an argument to the function.
推荐答案
如果我理解你的问题,应该像将 arg
更改为<一样简单code>此:
If I understand your question it should be as easy as changing arg
to this
:
fields.widget.attrs['onchange'] = 'execute_function(this)'
这篇关于如何将一个onChange事件添加到Django表单字段中,并将字段本身作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文