【发布时间】:2014-12-08 23:12:35
【问题描述】:
在 JQuery 中我正在尝试执行以下操作
- 找到页面上的每个链接
- HREF 属性以“#”开头的位置
- 并且 ID 值不是“mobileMenu”
这很好用:
$("a[href^='#']").each(function () { // links where HREF starts with #
if ($(this).attr('id') != 'mobileMenu') { // id not equal to mobileMenu
$(this).click(function () {
// logic
})
}
});
但是当我尝试将它组合成更简洁的搜索时,它失败了(mobileMenu 链接仍然被拉入数组):
$("a[href^='#'], a[id!='mobileMenu']").each(function () {
}
请问我做错了什么?
【问题讨论】:
标签: jquery