图像点击删除确认或取消HTML Javascript

时间:2016-04-27 08:31:29

标签: javascript html html5

我有一个图像,我想用作连接中表格行的删除连接。

我想使用javascript整合确认删除消息框。

这是表格行:

<td>
    <input type="image" name="submit" src="static/img/32/critical.png" alt="Delete Connection" onclick="(<%# Eval("id").ToString%>);clearText(<%= result.ClientID%>); CopyId(<%# Eval("id").ToString%>); return Message(<%# Eval("id").ToString%>)" />
</td>

这是脚本:

<script>
    function Message() {
        var txt;
        var ok = confirm("Are you sure you want to delete this connection");
        if (ok == true) {
            return true;
            txt = "Connection Deleted!";
            (<%# Eval("id").ToString%>);clearText(<%= result.ClientID%>); CopyId(<%# Eval("id").ToString%>);
        } else { 
            return false; 
            txt = "Cancelled";
        }
        document.getElementById("PopUp").innerHTML = txt;
    }
</script>

<p id="PopUp"></p>

当我点击图片时,它只是删除行和连接而不询问我。我希望它要求确认并采取相应行动。

如果为true则运行删除,否则则取消。

对此有点挣扎,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

尝试以下代码

    <script>
         function Message() {
             var txt ="";
             var ok = confirm("Are you sure you want to delete this connection");
             if (ok) {
                txt = "Connection Deleted!";
                // your code here

             } else { 
               txt = "Cancelled";

             }
             document.getElementById("PopUp").innerHTML = txt;
          }
    </script>