简体   繁体   English

Bootstrap Modal-使用具有有效外部HREF的锚点切换模态(用于备份)

[英]Bootstrap Modal - toggling modal with an anchor with a valid external HREF (for backup)

The reason for this to cover any user that MAY have javascript turned off. 涵盖任何可能已关闭javascript的用户的原因。 It's a company standard that we develop our web pages for this, since our demographic still have their VCR's blinking 12:00. 我们为此开发网页是公司的标准,因为我们的受众群体的VCR仍在12:00闪烁。

I have a text link that is being populated by a database call: 我有一个由数据库调用填充的文本链接:

<a href="article.html?aID=123" data-toggle="modal" data-target="#theModal" data-aid="123">Click for Article</a>

The common user experience is that the user will click the link, and it will toggle a modal displaying the article. 常见的用户体验是用户将单击链接,并将切换显示文章的模式。 BUT we want to incorporate a fallback in case the user has javascript turned off, so when the link is clicked, it will simply take the user to the article page and display the dynamic content loaded by padding the Article ID of 123. 但是我们希望在用户关闭javascript的情况下合并一个后备,因此,当单击链接时,它将简单地将用户带到文章页面,并通过填充文章ID为123来显示加载的动态内容。

Currently with Bootstrap properly loaded on the page, when the user clickson the link, it just goes to the article page and does NOT toggle the modal. 当前在页面上正确加载了Bootstrap的情况下,当用户单击链接时,它只会转到文章页面,并且不会切换模式。

What method do I need to add to a onClick event to prevent this click through from occuring, but still toggling the modal to display? 我需要向onClick事件添加什么方法以防止发生这种点击,但仍切换显示模式?

$('[data-toggle="modal"]').on('click', function(e){
     e.stopPropagation();
});

or 要么

$('[data-toggle="modal"]').on('click', function(e){
     e.preventDefault();
});

正确答案是e.preventDefault()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM