4

是否可以在 jQuery 的绑定方法中为自定义事件使用正则表达式。就像是...

$(selector).bind(myRegex, function(){})

例如,如果我有两个自定义事件 ,CustomerAdd并且CustomerDelete可以宣布,我希望能够监听Customer*.

4

1 回答 1

0

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...

于 2009-07-29T15:59:54.643 回答