jQuery 语法错误:#/ [英] jQuery syntax error: #/

查看:24
本文介绍了jQuery 语法错误:#/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的 Web 应用程序中使用 jQuery、Twitter Bootstrap 和 AngularJS.我一直在尝试进行路由,但是每当我尝试单击时间选项卡时,jQuery 都会不断给我 Syntax error, unrecognized expression: #/time,反之亦然.我不知道是什么导致了这个错误,除了它是由 # 号引起的.我已经广泛地搜索了谷歌,但无济于事.这是我的代码:

I am currently using jQuery, Twitter Bootstrap and AngularJS for my web application. I've been trying to do routing, but jQuery keeps giving me Syntax error, unrecognized expression: #/time whenever I try to click on the time tab, or vice versa. I have no idea which is causing this error, except that it is caused by the # sign. I have googled extensively but to no avail. Here is my code:

<ul class="nav nav-tabs">
  <li class="active">
    <a href="#/main" data-toggle="tab" id="main-tab">Main</a>
  </li>
  <li>
    <a href="#/time" data-toggle="tab" id="time-tab">Time Reports</a>
  </li>
</ul>

我需要保留斜杠,因为我将它用于我的 AngularJS 路由(即 index.html#/mainindex.html#/time 将加载不同的内容在我的一个 div 中).什么可能导致此错误?

I need to keep the slash as I use it for my AngularJS routing (i.e. index.html#/main and index.html#/time will load different content in one of my divs). What could possibly be causing this error?

推荐答案

我猜在指定目标的 idhref 中有额外的斜线.删除它们,它应该可以正常工作.

I guess extra slash in the href specifying id of the target. remove them and it should work fine.

<ul class="nav nav-tabs">
  <li class="active">
    <a href="#main" data-toggle="tab" id="main-tab">Main</a>
  </li>
  <li>
    <a href="#time" data-toggle="tab" id="time-tab">Time Reports</a>
  </li>
</ul>

Bootstrap 将 href 值视为要显示为选项卡内容的目标元素的 id.所以在这种情况下,它会寻找不存在的 id = #/time 的东西.

Bootstrap looks at the href value as id for the target element to be shown as tab content. SO here in this case it would be looking for something with id = #/time which doesn't exist.

如果你想保持 href 完整,你可以使用 data-target 属性

if you want to keep href intact you can use data-target attribute

<a href="#/main" data-toggle="tab" data-target="#main" id="main-tab">Main</a>

这篇关于jQuery 语法错误:#/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆