简体   繁体   English

语法错误: <a>链接无法通过单击操作,只能通过右键单击+“在新选项卡中打开链接”命令打开</a>

[英]Syntax error: <a> link not working by clicking, only opens by right click + “open link in new tab” command

When I click the 'Download Full Menu' link in this page ( http://www.brazenbbq.com/menus/restaurant/ ) it won't open unless I right click and 'Open link in a new tab'. 当我单击此页面( http://www.brazenbbq.com/menus/restaurant/ )中的“下载完整菜单”链接时,除非我右键单击并单击“在新选项卡中打开链接”,否则它将不会打开。 I used Chrome and Firefox element inspector and I get the below Jquery error, but I'm not sure how can I fix it since I'm just a javascript newbie... Thank you for your help! 我使用了Chrome和Firefox元素检查器,但收到以下Jquery错误,但由于我只是JavaScript新手,因此不确定如何解决此问题。感谢您的帮助!

 2jquery.js?ver=1.10.2:formatted:570 Uncaught Error: Syntax error, unrecognized expression: /wp-content/uploads/2013/11/Brazen_BBQ_Menu.pdf fa.error @ jquery.js?ver=1.10.2:formatted:570 fa.tokenize @ jquery.js?ver=1.10.2:formatted:898 fa.select @ jquery.js?ver=1.10.2:formatted:1069 fa @ jquery.js?ver=1.10.2:formatted:339 find @ jquery.js?ver=1.10.2:formatted:1188 n.fn.init @ jquery.js?ver=1.10.2:formatted:1211 n @ jquery.js?ver=1.10.2:formatted:22 (anonymous function) @ VM266:43 dispatch @ jquery.js?ver=1.10.2:formatted:2128 r.handle @ jquery.js?ver=1.10.2:formatted:2007 

尝试添加target="_blank"a标签

<a href="link.pdf" target="_blank">Some Link</a>

You have javascript that is hooking into the nav, expecting a #Item to link to (scrolls down). 您的JavaScript挂在导航栏上,期望#Item链接到(向下滚动)。

The link to the PDF is also in this nav, and so your jQuery plugin (or custom code) is trying to parse the "hash" (that it hasn't found) and then fails.... PDF的链接也位于此导航中,因此您的jQuery插件(或自定义代码)正尝试解析“哈希”(未找到),然后失败。...

in this line in the script ( animate scroll down to anchor script ) you have 在脚本的这一行(动画向下滚动以锚定脚本)中,

    $leftMenu(".fullMenuLeft a").on("click", function( e ) {

    e.preventDefault();

that's why your first link to pdf doesn't work as you want. 这就是为什么您的第一个pdf链接无法按您希望的那样工作。 plus...in the continuation of the script you use the href of this ...which is the fullMenuleft a href to do something different than what you expect from pdf link to do 加...脚本的延续使用hrefthis ...这是fullMenuleft a HREF做一些事情比你从PDF链接期望做什么不同

so change the above line to 所以将上面的行更改为

  $leftMenu(".fullMenuLeft li:not(.menuTitle) a").on("click", function( e ) {

  e.preventDefault();

so you will select all the li a except the first one , the one with link to pdf 因此,您将选择除第一个以外的所有li a ,其中一个带有pdf链接

When clicking on 'download full menu' your sticky menu-navigation plugin tries to scroll to the according position on the page. 单击“下载完整菜单”时,您的粘贴式菜单导航插件会尝试滚动到页面上的相应位置。 But as this download-link is not an anchor, Javascript throws an error. 但是由于此下载链接不是锚点,因此Javascript引发错误。 Try to change your click-handler selector to something like this: 尝试将您的点击处理程序选择器更改为如下所示:

$leftMenu(".fullMenuLeft a[href~='#']").on("click", function( e ) { ... }

With the attribute selector and tilde you can filter your links by the hash in the href attribute. 使用属性选择器和代字号,您可以按href属性中的哈希值过滤链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM