Nice Asked:2020-06-27 13:26:56 +0000 UTC2020-06-27 13:26:56 +0000 UTC 2020-06-27 13:26:56 +0000 UTC 在jQuery中使用属性分组选择器 772 如何在单个函数中引用 jQuery 中的一组元素? 例如链接: a[href^="page-1.html#"] 这种语法对我不起作用: $('a[href^="page-1.html#"]', 'a[href^="page-2.html#"]').click(function(e) { e.preventDefault(); }); jquery 1 个回答 Voted Best Answer artem55555p 2020-06-27T13:43:12Z2020-06-27T13:43:12Z 引号之间有逗号,但需要在引号内。 $('a[href^="page-1.html#"], a[href^="page-2.html#"]').click(function() { alert('Нажал'); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="page-1.html#">Ссылка 1</a> <a href="page-2.html#">Ссылка 2</a>
引号之间有逗号,但需要在引号内。