小编use*_*697的帖子

是否有任何不引人注目的方式来挂钩触发器的jQuery方法?

我想知道是否有任何不引人注目的方式来挂钩诸如attr,data,css等方法并调用自定义触发器?

理想情况下,我可以这样做:

$(".friend a").bind("attr.changed", changed /* data */, function(e) {
    alert("The " + changed.attribute + " attribute changed from " + changed.from + " to " + changed.to + "!");
});

$(".friend").append(
  $("<a/>").
    attr("href", "#").
    html("Friend 1").
    click(function() { alert('I was clicked!'); }); // creates the element, doesn't execute since element didn't exist

$(".friends a").each(function() {
  var $this = $(this);
  $this.attr("rel", "friend"); // triggers "attr.changed"
});
Run Code Online (Sandbox Code Playgroud)

理想情况下,这将能够在任何元素上触发,并将attr更改,从一个对象传递到每个jQuery方法内部的触发器调用.

javascript jquery

2
推荐指数
1
解决办法
1238
查看次数

标签 统计

javascript ×1

jquery ×1