JQuery href 上的多个 :not() 选择器不起作用
JQuery multiple :not() selector on href not working
我试图用多个 :not()
选择器来欺骗我在网上找到的脚本。不幸的是我找不到为什么它不起作用...
脚本的目的是在单击时滚动到锚点。但是我有一个响应式菜单 包含一个名为 #menu
的锚定 link。所以我试图将它从函数中排除。这是我的选择器:
$(function() {
$('a[href*=#]:not([href=#]):not([href*='menu'])').click(function() {
myfuntion
});
感谢您的帮助:)
将menu
周围的单引号改为双引号
$('a[href*=#]:not([href=#]):not([href*="menu"])').click(function() { myfuntion });
在单引号内 'something here'
您只能使用双引号 ""
以保留在 String
上下文中
'something "foo" bar'
否则解析器将期望 string/variable 串联:
'something'+ foo +'bar' // << correct concatenation with foo variable
否则会抛出
'something' foo 'bar' // << Unexpected identifier / Syntax Error
我试图用多个 :not()
选择器来欺骗我在网上找到的脚本。不幸的是我找不到为什么它不起作用...
脚本的目的是在单击时滚动到锚点。但是我有一个响应式菜单 包含一个名为 #menu
的锚定 link。所以我试图将它从函数中排除。这是我的选择器:
$(function() {
$('a[href*=#]:not([href=#]):not([href*='menu'])').click(function() {
myfuntion
});
感谢您的帮助:)
将menu
周围的单引号改为双引号
$('a[href*=#]:not([href=#]):not([href*="menu"])').click(function() { myfuntion });
在单引号内 'something here'
您只能使用双引号 ""
以保留在 String
上下文中
'something "foo" bar'
否则解析器将期望 string/variable 串联:
'something'+ foo +'bar' // << correct concatenation with foo variable
否则会抛出
'something' foo 'bar' // << Unexpected identifier / Syntax Error