有没有办法自定义“确认”文本框中显示的对话框以反映您引用的项目?我在想像......
OnClientClick="return confirm('Are you sure you want to delete' + '<%# Eval("Name") %>')"
但我一直认为服务器标签不是很好。&#39;我尝试使用此格式时出错。有谁知道解决方案?
答案 0 :(得分:0)
这应该有用......我不知道任何ASP,但在PHP中它会像:
OnClientClick="return confirm('Are you sure you want to delete <?php echo $name; ?>')"
在你的情况下,我猜它应该是这样的:
OnClientClick="return confirm('Are you sure you want to delete <%# Eval("Name") %>')"
答案 1 :(得分:0)
您可以在javascript中使用“this”对象来了解上下文
例如:
<head runat="server">
<title></title>
<script type="text/javascript">
function tryDelete(button) {
var itemName = getItemName(button);
return confirm("Are you sure you want to delete '" + itemName + "'?");
}
function getItemName(button) {
return button.parentElement.parentElement.children[1].innerHTML;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:Button ID="cmdDelete" runat="server" Text="delete" OnClientClick="return tryDelete(this);" /></td>
<td>Item 1</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="delete" OnClientClick="return tryDelete(this);" /></td>
<td>Item 2</td>
</tr>
</table>
</form>
</body>