首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击按钮时注销ASP.NET核心网络应用程序

单击按钮时注销ASP.NET核心网络应用程序
EN

Stack Overflow用户
提问于 2017-07-20 20:07:49
回答 1查看 679关注 0票数 0

基本上,我想在用户单击对话框中的按钮时从我的web应用程序中注销用户。尝试搜索并尝试以下代码,但在单击该按钮时都不起作用。我使用sweetalert.js显示对话框,并使用以下代码放置一个html按钮

代码语言:javascript
复制
<form action='/logout' method='post' id='logout_form'>
  <a onclick='document.getElementById('logout_form').submit();' style='cursor: pointer;'>Log Out</a>
</form>

插入到对话框主体中,但是按钮将不起作用,相反,我在javascript中得到一个Uncaught SyntaxError: Unexpected token }错误。以下是我可爱的提醒代码:

代码语言:javascript
复制
             swal({
                    title: "Logout? Any data you've entered will not be saved.",
                    text: "<form action='/logout' method='post' id='logout_form'><a onclick='document.getElementById('logout_form').submit();' style='cursor: pointer;'>Log Out</a></form>",
                    html: true,
                    type: "warning",
                    showCancelButton: "No",
                    confirmButtonColor: "#D9534F",
                    confirmButtonText: "Yes, cancel it!",
                    closeOnConfirm: false
                });

会出什么问题呢?提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-07-20 21:34:18

您的引号和双引号有问题您的锚点定义无效,因为logout_form之前的单引号会终止字符串。

虽然用双引号括起来,但这不是问题,因为只有双引号才会标记字符串的边界:

代码语言: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:

代码语言:javascript
复制
text: "<form action='/logout' method='post' id='logout_form'><a onclick='document.getElementById(\'logout_form\').submit();' style='cursor: pointer;'>Log Out</a></form>",

除非你还没有发布代码中的任何其他语法错误,这应该可以解决你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45214253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档