在grails中获取点击提交按钮的名称 [英] Get name of clicked submit button in grails

查看:66
本文介绍了在grails中获取点击提交按钮的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单中,我有两个提交按钮:

On a form I have two submit buttons:

<g:submitButton name="add" value="Add"/>
<g:submitButton name="addAnother" value="Add and Create Another"/>

基于使用哪个按钮提交表单,我需要采取稍微不同的操作。如何在控制器中获取点击按钮的名称?

I need to take slightly different action based on which button was used to submit the form. How to I get the name of the clicked button in my controller?

推荐答案

点击按钮的名称以params结尾:

The name of the clicked button ends up in params:

if(params["addAnother"])
   doThis()
else
   doThat()

这篇关于在grails中获取点击提交按钮的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆