0

我不确定为什么这种情况不断发生。我搜索了如何从 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 中,到目前为止,我很难让它发挥作用。对此的任何帮助将不胜感激!

4

1 回答 1

0

在点击事件回调中,你设置的那一行window.location.hash = $(this).attr('href');,这会导致在你设置的内容之前加上一个'#'前缀,即href属性的值。

于 2018-07-07T19:29:37.037 回答