I have the following:
我有以下内容:
$("#article").on('click',
'a[href^="/C"], a[href^="/Java"], a[href^="/T"]', function (event) {
Can this be simplified to not repeat the "href" so many times. Can I use a different kind of regular expression?
这可以简化为不重复“href”这么多次。我可以使用不同类型的正则表达式吗?
2 个解决方案
#1
6
The best option would be is to give the all the three anchor tags a single class Name
..
最好的选择是给所有三个锚标签一个类名。
$("#article").on('click', 'a.planguages', function (event) {
Or any other selector that is common for these three..
或者这三个常见的任何其他选择器..
Otherwise you cannot remove the href
as that looks unique to the anchor tags in context.
否则,您无法删除href,因为它对于上下文中的锚标记而言看起来是唯一的。
#2
0
At least make that one work
至少让那个工作
$("#article").on("click", 'a[href^="/C"]', 'a[href^="/Java"]', 'a[href^="/T"]', "function(event){}")
#1
6
The best option would be is to give the all the three anchor tags a single class Name
..
最好的选择是给所有三个锚标签一个类名。
$("#article").on('click', 'a.planguages', function (event) {
Or any other selector that is common for these three..
或者这三个常见的任何其他选择器..
Otherwise you cannot remove the href
as that looks unique to the anchor tags in context.
否则,您无法删除href,因为它对于上下文中的锚标记而言看起来是唯一的。
#2
0
At least make that one work
至少让那个工作
$("#article").on("click", 'a[href^="/C"]', 'a[href^="/Java"]', 'a[href^="/T"]', "function(event){}")