【发布时间】:2017-07-05 19:59:06
【问题描述】:
已经有一些关于此的帖子,this one 再简单不过了。出于某种原因,虽然我无法让元素链接到 href 属性。
这是需要链接的元素的类:.vc_tta-tab:nth-child(1);
页面上有一个锚点#about;
这是我正在使用的 jQuery:
<script>
jQuery('.vc_tta-tab:nth-child(1)').prop('href','https://example.com/#about');
</script>
这个想法是使用.vc_tta-tab:nth-child(1) 元素链接到页面上的/#about 部分。
请有人帮我纠正我做错了什么?
【问题讨论】:
-
使用
attr代替prop -
@RAUSHANKUMAR 谢谢,我试过了,不幸的是它也不起作用
-
在什么情况下它不起作用?您遇到了哪些控制台错误?
-
@jmargolisvt 我收到了
Uncaught Error: Syntax error, unrecognized expression: #,请看这里:s23.postimg.org/45fww8kaj/… -
那张截图没有用...您需要提供更多代码,此代码不是这里的问题...这工作正常
标签: javascript jquery attributes