【问题标题】:Grails - Execute Table Row Deletion depending on confirm() prompt messageGrails - 根据确认()提示消息执行表行删除
【发布时间】:2017-08-26 00:32:13
【问题描述】:

我有一个包含员工的表,该表有一个删除按钮。按下此按钮时,会在没有任何确认消息的情况下进行行删除。

所以我尝试添加这样一个确认()对话框提示,但我无法正确控制发生的情况,因为无论我做什么,行删除总是会发生。这是因为下面的代码:

.gsp 页面:

<td class="text-center">
    <g:link controller="employee" action="deleteRecord" params="${[id: celldata.get('id')]}">
            <button type="button" class="btn btn-danger" onclick="getConfirmation();">Delete</button>
    /g:link>
</td>

javascript 代码:

function getConfirmation() {
    var retVal = confirm("Are you sure you want to delete ?");
    if( retVal == true ){
        alert("User wants to delete!");
        return true;
    }
    else{
        alert ("User does not want to delete!");
        return false;
    }
   }

无论我在提示信息中添加什么内容,employeeController 中的 deleteRecord 函数都会一直执行。如何根据confirm()提示符的消息停止deleteRecord函数的执行?

小提琴位于here

【问题讨论】:

  • Graills 过去并且可能仍然会提供带有删除功能的默认 show.gsp:onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');"

标签: javascript jquery sql grails


【解决方案1】:

您可以将onclick="getConfirmation();" 更改为onclick="return getConfirmation();" 以防止点击的默认操作。

没有return,你的函数getConfirmation的返回值将不会被使用。

如果不显式返回,可以将事件传递给函数,并在函数体中添加event.preventDefault();

【讨论】:

  • 哇,我期待一个更难的解决方案来解决我的问题,嗯,再次感谢@aristotll
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2014-07-19
  • 2013-12-10
  • 2015-11-25
  • 2020-02-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多