html – 锚标记作为提交按钮?
发布时间:2020-12-24 22:21:00 所属栏目:资源 来源:网络整理
导读:我正在将现有网站转换为使用MVC和实体框架. 布局/样式应该保持不变,为了遵循该指南,我需要使用 a提交我的登录表单.标签,因为它有按钮的自定义图像. 这是我的表格: @using (Html.BeginForm("Login","Login",FormMethod.Post,new { id = "login",action = "
我正在将现有网站转换为使用MVC和实体框架. 布局/样式应该保持不变,为了遵循该指南,我需要使用< a>提交我的登录表单.标签,因为它有按钮的自定义图像. 这是我的表格: @using (Html.BeginForm("Login","Login",FormMethod.Post,new { id = "login",action = "Login" })) { <label> <span>Username </span> <input type="text" name="UserName" id="UserName" class="input-text required" /> </label> <label> <span>Password </span> <input type="password" name="Password" id="Password" class="input-text required" /> </label> <label> <input type="checkbox" name="RememberMe" id="RememberMe" class="check-box" /> <span class="checkboxlabel">Remember Me</span> </label> <div class="spacer"> <a href="javascript:void(0)" onclick="login();" class="login-button"></a> </div> } 如您所见,< a>标签以前使用javascript提交登录信息.这不是我想要完成的. 如何更改该标签以将我的表单提交给我的控制器操作? 解决方法我做了一些小改动HTML <form action="test.aspx" type="POST"> <label> <span>Username</span> <input type="text" name="UserName" id="UserName" class="input-text required" /> </label> <label> <span>Password</span> <input type="password" name="Password" id="Password" class="input-text required" /> </label> <label> <input type="checkbox" name="RememberMe" id="RememberMe" class="check-box" /> <span class="checkboxlabel">Remember Me</span> </label> <div class="spacer"> <a href="javascript:void(0)" class="login-button">Login</a> </div> </form> jQuery的 $(document).ready(function(){ $(document).on("click",".login-button",function(){ var form = $(this).closest("form"); //console.log(form); form.submit(); }); }); JSFiddle (编辑:上海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |