想要一个确认框,如果你想使用jsp和java脚本删除数据

时间:2013-11-14 04:53:37

标签: javascript jsp

我尝试了一些但没有得到任何东西...... 当我点击删除链接我必须得到一个确认框但我没有得到它.. 谁能建议我?

JSP

urlencrypt:url value="abc.action" htmlEscape="true" var="removeLink"/>
<td><a href="removeLink"  onclick="confirmRemoveQuestion('${removeLink}')">
<fmt:message key="link.remove" /></a>&nbsp;&nbsp;&nbsp;&nbsp;</td>

的javascript

<script type="text/javascript">
var confirmRemoveDialog;
var confirmOkUrl=  ; 

function setRemoveQuestionDialog()
{
    var handleYes = function() { 
        window.location = confirmOkUrl;
        this.hide(); 
    };

    var handleNo = function() { 
        this.hide();
    };

    var confDialogButtons = [ { text:"<fmt:message key="link.cancel"/>", handler:handleNo, isDefault:true}, 
                                { text:"<fmt:message key="link.ok"/>",handler:handleYes } 
                              ];

    confirmRemoveDialog = getConfirmOKDialog(confDialogButtons);
}

function confirmRemoveQuestion(url)
{
    confirmOkUrl = url;
    setRemoveQuestionDialog();
    showConfirmDialog(confirmRemoveDialog, "<fmt:message key="removeLink.confirmMessage"/>");
}
</script>

2 个答案:

答案 0 :(得分:2)

使用以下简单代码

<script>
function confirmRemoveQuestion(link){
    if(show_confirm()){
     window.location = link;
     this.hide(); 
    }
    else{
     this.hide();  
    }
}
function show_confirm()
{
  return confirm("Are you sure you want to do this?");
}
</script>

<td><a href="#"  onclick="confirmRemoveQuestion('${removeLink}')"> <!--removLink-->
<fmt:message key="link.remove" /></a>&nbsp;&nbsp;&nbsp;&nbsp;</td>

答案 1 :(得分:1)

你知道吗

showConfirmDialog(confirmRemoveDialog, "<fmt:message key="removeLink.confirmMessage"/>");

在语法上是不正确的?调试会告诉你这个。