我有一个图像,我想用作连接中表格行的删除连接。
我想使用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则运行删除,否则则取消。
对此有点挣扎,所以任何帮助都会受到赞赏。
答案 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>