当我打开Bootstrap Modal时,标签不断出现吗?

时间:2018-07-07 18:33:24

标签: javascript jquery html anchor href

我不确定为什么这种情况持续发生。我搜索了如何从URL中删除主题标签,并找到了许多答案。他们所有人都没有帮助,因为他们所做的只是删除主题标签,但是我必须刷新页面。即使那样,那仍然没有帮助。我的问题是,当我单击此锚标记时,井号标签会出现:

echo '<a  href="?id='.$row['id'].'" <-- here is what I am trying to add to the URL, but the hashtag appears. id="smallbtn" data-toggle="modal" data-target="#small"  data-modal="small">';

这是我用来尝试解决问题的javascript,但没有成功(还被告知要在<head>中使用它。):

 <script type="text/javascript">
// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");

// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}
</script>

我不知道这是否是问题,但是我用它来打开模式并将锚标记href放入URL:

    <script type="text/javascript">
$(document).ready(function(){
   $(window.location.hash).modal('show');
   $('a[data-toggle="modal"]').click(function(){
      window.location.hash = $(this).attr('href');
   });
});
</script>

我的目标是尝试将href放在URL中作为参数,到目前为止,我很难实现这一目标。对此,我们将提供任何帮助!

1 个答案:

答案 0 :(得分:0)

在click事件回调中,您设置*p的行,这将导致在您设置的内容(即href属性的值)之前加一个'#'前缀。