无法使用 $(“#tag”).click() 停止浏览器导航
我正在尝试创建一个名为 SignIn 的按钮,该按钮适用于没有 JavaScript 的浏览器,但在启用 JavaScript 时不会导航。
<script type="text/javascript">
$(function () {
$("#signIn").click(function () {
//
// Stop event bubbling
//
return false;
});
});
// Gets the div tag and its content for an identity provider
function GetIdentityProviderTag(idp, index)
{
return '<div class="identity-provider" id="button' + index + '"><button>' + idp.Name + ' </button></div>';
}
</script>
<div>
<a href="/NoJavascriptSignIn" id="signIn">Sign In</a>
</div>
我需要做什么才能允许启用 javascript 和禁用 javascript 的浏览器都能工作?
I am trying to create a button called SignIn that accommodates browsers without javascript, but doesn't navigate when Javascript is enabled.
<script type="text/javascript">
$(function () {
$("#signIn").click(function () {
//
// Stop event bubbling
//
return false;
});
});
// Gets the div tag and its content for an identity provider
function GetIdentityProviderTag(idp, index)
{
return '<div class="identity-provider" id="button' + index + '"><button>' + idp.Name + ' </button></div>';
}
</script>
<div>
<a href="/NoJavascriptSignIn" id="signIn">Sign In</a>
</div>
What do I need to do to permit both javascript enabled, and javascript disabled browsers to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下一个代码片段阻止浏览器跟踪链接(主要是
return false
),您应该将其删除:如果您只想自动按下按钮,请使用:
The next code snippet prevents the browser from following the link (mainly
return false
), you should remove it:If you just want to press the button automatically, use:
要停止链接单击的默认操作,您需要添加:
到您的脚本 因此它看起来像这样
PreventDefault() 会取消该事件(如果它是可取消的),而不停止该事件的进一步传播。
To stop the default action of a link click you need to add:
To your script So it will look something like
The preventDefault() cancels the event if it is cancelable, without stopping further propagation of the event.
你可以尝试
You could try