表单登录不与锚#工作
FORM Login not working with Anchor #
我有以下表单提交代码
<div class="top-links">
<ul>
<li><a href="javascript:void(0);">Sign In</a>
<div class="top-link-section">
<form id="top-login" role="form" action="">
<div class="input-group" id="top-login-username">
<input type="text" class="form-control" name="username" placeholder="Username" required>
</div>
<div class="input-group" id="top-login-password">
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="input-group" id="top-login-remember">
<label><input type="checkbox" value="yes" name="remember_me"> Remember me</label>
</div>
<button class="btn btn-danger btn-block" type="submit">Sign In</button>
</form>
</div>
</li>
</ul>
</div>
如果用户在登录之前没有点击页面中的任何锚链接,那么表单登录工作正常。
工作正常
http://example.com/index.php
但是,如果页面url变成类似于(url地址后面有锚#)
http://example.com/index.php#
,因为我得到了一些
的链接<a href="#">Events</a>
如果用户点击事件看到一些弹出之前,他们登录,登录表单将不工作,我如何处理这种情况,以确保登录仍然进行,即使在url地址#。
——假设登录后总是返回
example.com/index.php但我更喜欢如果它可以example.com没有index.php
如果下面的代码把#放在页面的末尾,那么你可以让它返回false,当用户点击这个点击时不做任何事情,只是打开弹出窗口。
<a href="#">Events</a>
你可以使用纯JS或jQuery来实现相同的功能。
所以像这样修改这些元素的HTML,
<a href="#" onclick="return eventClickBtn();">Events</a> <!-- for plain JS -->
<a href="#" class="eventCommonBtn">Events</a> <!-- for plain jQuery -->
在JS端,你需要添加以下内容:
<script>
function eventClickBtn() {
// Your logic to open popupbox
return false;
}
// For jQuery
$('.eventClickBtn').click(function(e){
e.preventDefault();
});
</script>
使用
中提到的超链接event.preventDefault();
默认动作的事件将不被触发,对于普通的JS也是如此。如果返回false,则不会启动href
相关文章:
- Facebook登录按钮没有'不能在Firefox上工作
- 让typescript与facebook登录为Angular 2项目工作
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- firebase登录与离子不工作
- Omniauth Facebook登录无法工作
- 登录控制台可以工作,但会立即导致TypeError
- 登录表单 jQuery 插件无法按预期工作
- 通过登录和在线照片显示上传照片的工作流程
- 我有三个地方供用户登录,在同一页面上,我如何在一个功能中让所有三个按钮工作和三个表单处理
- Facebook自动登录JS在控制台中工作,但在GM脚本中不起作用
- 登录验证 JavaScript 无法正常工作
- PHP 登录页面无法正常工作
- Angularjs 登录 cookie 第二次工作
- 登录按钮和身份验证可以在Internet explorer中工作
- 使用设置元素值登录;没有按预期工作
- Facebook登录在浏览器中运行良好,但没有;我不能用phonegap在安卓系统上工作
- 在使用Ajax提交Devise登录表单后,如何让jQuery.on()工作
- 流星:谷歌登录不'不能在iphone/ipad上工作
- Document.ready无法在我的登录页面上工作
- 我如何添加一个在不同域工作的网络小部件的facebook登录名