public function removeSelectedCategory()
{
echo "<script>var r=confirm('Are you sure you want to delete this category?'); </script>";
if($r==true)
{
some code goes here
}
我写过类似的东西。现在我想删除一些东西,但我希望用户在删除之前确认它。此功能在控制器内部。
答案 0 :(得分:2)
您可以在生成按钮,链接或任何需要确认时提供JavaScript代码。例如:
<a href="..." onclick="return confirmDelete();">Delete category</a>
<!-- or -->
<input type="submit" name="delete" value="Delete" onclick="return confirmDelete();" />
<script type="text/javascript">
function confirmDelete() {
return confirm('Are you sure you want to delete this category?');
}
</script>
这样,只有当用户在确认对话框中按“确定”时,才会激活链接/按钮。