Javascript 单击按钮时注销ASP.NET核心Web应用程序
基本上,我希望用户在单击对话框中的按钮时,立即从我的web应用程序中注销。尝试四处搜索并尝试以下代码,但单击按钮时没有任何效果。我使用sweetalert.js来显示对话框,我只是用下面的代码放了一个html按钮Javascript 单击按钮时注销ASP.NET核心Web应用程序,javascript,html,asp.net,sweetalert,Javascript,Html,Asp.net,Sweetalert,基本上,我希望用户在单击对话框中的按钮时,立即从我的web应用程序中注销。尝试四处搜索并尝试以下代码,但单击按钮时没有任何效果。我使用sweetalert.js来显示对话框,我只是用下面的代码放了一个html按钮 <form action='/logout' method='post' id='logout_form'> <a onclick='document.getElementById('logout_form').submit();' style='cursor:
<form action='/logout' method='post' id='logout_form'>
<a onclick='document.getElementById('logout_form').submit();' style='cursor: pointer;'>Log Out</a>
</form>
有什么不对劲吗?提前感谢。您的引号有问题,双引号您的锚定定义无效,因为注销前的单引号表单会终止字符串 虽然使用双引号包装,但这不是问题,因为只有双引号将标记字符串的边界:
{ text: "<form action='/logout' method='post' id='logout_form'><a onclick='document.getElementById('logout_form').submit();' style='cursor: pointer;'>Log Out</a></form>" }
{text:“注销”}
这意味着您应该转义/屏蔽引号,以防止解析器抛出错误和错误解释以下javascript:
text: "<form action='/logout' method='post' id='logout_form'><a onclick='document.getElementById(\'logout_form\').submit();' style='cursor: pointer;'>Log Out</a></form>",
文本:“注销”,
除非您尚未发布的代码中存在任何其他语法错误,否则这应该可以解决您的问题。什么是“将不起作用”?你有javascript错误吗?.Net异常?抱歉,我忘了提到我在Javascript中收到了一个
未捕获的SyntaxError:Unexpected token}
,但只有在单击按钮时才收到。请编辑您的问题以包含该信息。好的,问题已用最新信息更新!
text: "<form action='/logout' method='post' id='logout_form'><a onclick='document.getElementById(\'logout_form\').submit();' style='cursor: pointer;'>Log Out</a></form>",