【发布时间】:2015-11-29 09:40:40
【问题描述】:
我遇到了一个可爱的语法错误。当我尝试选择所有没有包含占位符 URL 的 href 的锚标记时,即href="#"。
我尝试了以下方法:
$("a:not(href='#')");
//swapped single with double quotes
$('a:not(href="#")');
// no quotes at all
$("a:not(href=#)");
// wildcard selector
$("a:not(href*=#)");
所有这些都会导致以下错误:
未捕获的错误:语法错误,无法识别的表达式:href=#(…)
有什么想法吗?
以下片段:
var $item = $("a:not(href='#')");
console.log($item);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="http://google.com">Selected</a>
<a href="#">Not selected</a>
【问题讨论】:
-
@Vohuman 我做到了。我只是忽略了它。
标签: javascript jquery jquery-selectors