【发布时间】:2009-01-13 18:01:22
【问题描述】:
我想知道是否有任何不显眼的方式来挂钩 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"
});
理想情况下,这将能够在任何元素上触发,并将对象中更改的 attr、from 和 to 传递给每个 jQuery 方法内部的触发器调用。
【问题讨论】:
标签: javascript jquery