简体   繁体   English

如何将JavaScript确认答案传递给Grails控制器?

[英]How to pass a javascript confirm answer into Grails controller?

I have an actionSubmit that right now does some work once the user hits the submit button. 我有一个actionSubmit,一旦用户点击了提交按钮,现在就可以做一些工作。 I want to be able to have the user click the button and have a confirm (Cancel/OK) show up and the user answers it. 我希望能够使用户单击按钮并显示确认(取消/确定),然后用户回答。 The submission should take place either way, but I'd like to pass the results of the confirm box to the controller to act on. 提交应该以任何一种方式进行,但是我想将确认框的结果传递给控制器​​以采取行动。

Basically the action will need to happen, but the user's answer to the confirm (Cancel/OK box) will drive some side effect. 基本上将需要执行该操作,但是用户对确认的回答(“取消/确定”框)将产生一些副作用。 The wording of the confirm box will say something like "Press OK to clear this field, press cancel to leave it be", but the button they clicked will still do its job. 确认框的措词将类似于“按OK清除此字段,按Cancel保留它”,但是他们单击的按钮仍会起作用。

Can anyone help me with this? 谁能帮我这个? Right now we just have an actionSubmit: 现在,我们只有一个actionSubmit:

 <g:actionSubmit class="save" action="selectTurn"
 value="Select Current Player" />

So the "Select Current Player" is the option they're pressing. 因此,他们选择的是“选择当前播放器”。 The end result will be to show this confirm box only in a certain case (I think I have a solution to that), and then the user will be asked "Would you like to clear this thing?" 最终结果将是仅在特定情况下显示此确认框(我认为我对此有解决办法),然后用户将被问到“您是否想清除此内容?”。 like I described above, and either result still selects a current player, with Cancel leaving the thing not cleared and OK clearing the thing, all can be done inside the controller/method save.selectTurn. 就像我上面所描述的,任一个结果仍然会选择一个当前播放器,在“取消”下不清除内容,在“确定”清除情况下,所有操作都可以在控制器/方法save.selectTurn中完成。

Does that make sense? 那有意义吗?

You can use Javascript by adding an onclick event like the examples below: 您可以通过添加onclick事件来使用Javascript,例如以下示例:

Generated by Scaffolding: 由脚手架产生:

onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"

Simple: 简单:

onclick="return confirm('Are you sure?');"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM