admin管理员组文章数量:1180551
I am trying to add an external http:// link on my bootstrap drop-down menu, but it always cause an
Uncaught Error: Syntax error, unrecognized expression: /
Here's the code I used with jQuery v1.11.3 and bootstrap v3.3.5
<nav class="main-navi">
<div class="webinarlink"><a class="btn btn-danger btn-block" data-target="#" style="background-color:#EA4A2B;margin:auto;" href="/" target="_blank"><i class="icon-users"></i>Webinar</a></div>
<ul>
<li class="active"><a class="scroll-up" href="#home"><i class="fa fa-home"></i> Home</a></li>
<li class=""><a class="scroll" href="#features">Features</a></li>
<li class=""><a class="scroll" href="#testimonials">Testimonials</a></li>
<li class=""><a class="scroll" href="#pricing">Prices</a></li>
<li class="has-dropdown"><a class="scroll" href="#">Help<i class="fa fa-caret-down"></i></a>
<ul class="dropdown">
<li class=""><a class="scroll" href="#faq"><i class="fa fa-question-circle"></i> FAQ</a></li>
<li class=""><a class="scroll" href="#team"><i class="fa fa-info-circle"></i> About Us</a></li>
<li class=""><a class="scroll" href="#contus"><i class="fa fa-envelope"></i> Contact Us</a></li>
<li class=""><a href="#pricing" class="scroll" onclick="Tawk_API.toggle();"><i class="fa fa-comments"></i> Chat with Us</a></li>
</ul>
</li>
</ul>
</nav>
I tried adding data-target="#" but it didn't work.
I am trying to add an external http:// link on my bootstrap drop-down menu, but it always cause an
Uncaught Error: Syntax error, unrecognized expression: http://example.com/
Here's the code I used with jQuery v1.11.3 and bootstrap v3.3.5
<nav class="main-navi">
<div class="webinarlink"><a class="btn btn-danger btn-block" data-target="#" style="background-color:#EA4A2B;margin:auto;" href="http://example.com/" target="_blank"><i class="icon-users"></i>Webinar</a></div>
<ul>
<li class="active"><a class="scroll-up" href="#home"><i class="fa fa-home"></i> Home</a></li>
<li class=""><a class="scroll" href="#features">Features</a></li>
<li class=""><a class="scroll" href="#testimonials">Testimonials</a></li>
<li class=""><a class="scroll" href="#pricing">Prices</a></li>
<li class="has-dropdown"><a class="scroll" href="#">Help<i class="fa fa-caret-down"></i></a>
<ul class="dropdown">
<li class=""><a class="scroll" href="#faq"><i class="fa fa-question-circle"></i> FAQ</a></li>
<li class=""><a class="scroll" href="#team"><i class="fa fa-info-circle"></i> About Us</a></li>
<li class=""><a class="scroll" href="#contus"><i class="fa fa-envelope"></i> Contact Us</a></li>
<li class=""><a href="#pricing" class="scroll" onclick="Tawk_API.toggle();"><i class="fa fa-comments"></i> Chat with Us</a></li>
</ul>
</li>
</ul>
</nav>
I tried adding data-target="#" but it didn't work.
Share Improve this question edited Feb 21, 2016 at 17:32 T.J. Crowder 1.1m199 gold badges2k silver badges1.9k bronze badges asked Feb 21, 2016 at 17:26 Joseph RaphaelJoseph Raphael 3482 gold badges3 silver badges13 bronze badges 5 |6 Answers
Reset to default 16If you are stuck on old Bootstrap then you can patch getParent
function of bootstrap-dropdown.js
.
Just replace $parent = selector && $(selector)
with this:
if (selector && selector !== '#') {
$parent = $(selector)
}
The issue has been fixed by following these steps:
- Use latest version of jQuery v2.1.3 and bootstrap v3.3.6
- Load Bootstrap JS after jquery in order
- Using data-target="#" with href="#" and put the external link on an onClick() trigger.
Hope it helps.
In my case, I had a script that automatically switches the "active" class on menu items on scroll, all the 'href' of the 'a' html tags under the Boostrap menu must not equal to "#", this solution worked for my case, if anyone has a similar case.
Here is my solution to the getParent function in bootstrap
function getParent($this) {
var selector = $this.attr('data-target')
if (!selector) {
selector = $this.attr('href')
selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
}
//var $parent = selector && $(selector)
var $parent = null;
if (selector && selector !== '#') {
$parent = $(selector)
}
return $parent && $parent.length ? $parent : $this.parent()
}
Please check JQuery added in your page. Mostly this type of error comes due to 2 or more jquery versions
When using Bootstrap 2.0.4 and jQuery 3+, find the toggle
function definition in dropdown.js
or bootstrap.js
and find the line that says:
$parent = $(selector);
On the line before, put:
selector = selector && selector !== "#" ? selector : null;
本文标签:
版权声明:本文标题:javascript - Bootstrap dropdown Jquery Uncaught Error: Syntax error, unrecognized expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738125856a2065031.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
main-navi
i guess the problem comme from it. – Zakaria Acharki Commented Feb 21, 2016 at 18:12