是否可以在 jQuery 的绑定方法中为自定义事件使用正则表达式。就像是...
$(selector).bind(myRegex, function(){})
例如,如果我有两个自定义事件 ,CustomerAdd
并且CustomerDelete
可以宣布,我希望能够监听Customer*
.
If you're trying to use a regex to select only certain DOM elements, you can use the .filter() method to pass in a function that would then perform regex logic to filter out the elements that don't match.
$(selector).filter(function (index) {
return /myregex/.test($(this).attr("id"));
})
Otherwise it's not too clear what you're trying to do...