web2py:如何将 javascript 添加到 Web2py Crud 表单?
使用 Web2Py。我试图将一些 javascript 附加到字段(onchange)或表单(onsubmit),但我认为绝对没有办法将这样的参数传递给 crud.create 或 form.custom.widget。
有人有主意吗?
Working with Web2Py. I'm trying to attach some javascript either to a field (onchange) or to the form (onsubmit), but I see absolutely no way to pass such argument to crud.create or to form.custom.widget.
Anyone has an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然有办法。适当的方法是询问 web2py 邮件列表上知道如何操作的人,而不是询问一般的堆栈溢出用户,他们会猜测错误的答案。 :-)
不管怎样,假设你有:
你可以做
Element 采用 css3/jQuery 语法(但它是在 python 中计算的)。
Of course there is a way. The appropriate way is to ask people on the web2py mailing list who know how to, as opposed to generic stack overflow users who will guess an incorrect answer. :-)
Anyway, assume you have:
You can do
Element takes the css3/jQuery syntax (but it is evaluated in python).
我不相信有办法直接做到这一点。一种选择是只操作 web2py 生成的 HTML,它只是一个字符串。在我看来,更干净的方法是使用 jQuery 的 $(document).ready() 函数绑定事件。
假设您有一个数据库表(所有内容都是从 web2py 的文档中窃取的):
使用表单:
嵌入视图中(以最简单的方式):
并且您想要将 onblur 处理程序添加到名称输入字段(添加到视图中):
I do not believe there is a way to do this directly. One option is just to manipulate web2py generated HTML, it is just a string. Even cleaner, in my opinion, is just to bind the event using jQuery's $(document).ready() function.
Say you have a database table (all is stolen from web2py's docs):
With form:
Embedded in a view (in the simplest manner):
And you want to add an onblur handler to the name input field (added to the view):