window.location.hash

时间:2016-11-25 10:03:00

标签: javascript ruby-on-rails

我有rails应用程序,我修改了一些文件,然后运行bundle instal和assets:precompile。

之后我文件中的错误没有改变。 发生错误的文件的一部分:

<script type="text/javascript">
function openCurrentTab() {
var hash = window.location.hash || '#info'
$('a[href=' + hash + ']').tab('show')
}

$(function() {
openCurrentTab()

$('#outage-tabs > li > a').click(function(evt) {
  evt.preventDefault()
  $(this).tab('show')
  history.pushState(null, null, this.hash)
})
})
window.onpopstate = openCurrentTab
</script>

错误(在控制台中)

application-76c7fea….js:24 Uncaught Error: Syntax error, unrecognized    expression: a[href=#info]

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

您的jQuery搜索中似乎有错误

$('a[href=' + hash + ']').tab('show')

使用end-with选择器和下一个语法:不要使用#inside term,使用&#39;&#39;用于设置搜索词

$("a[href$='hash-without-#-symbol']")

https://api.jquery.com/attribute-ends-with-selector/

答案 1 :(得分:0)

在更新公共/资产文件之前恢复也有帮助