在append()上做某事 [英] on append() do something
本文介绍了在append()上做某事的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当元素附加到DOM时是否可以添加某种事件/处理程序??
Is it possible to add some kind of an event/handler when an element is appended to the DOM...?
.click()、. change()、. keyup()等...
.click(), .change(), .keyup() etc. alike...
我需要在附加元素后立即获取其高度,然后将其设置为另一个元素
I need to get the height of an element as soon as it is appended and then set the height to another element
推荐答案
您可以覆盖默认的append方法,并使其触发自定义的追加事件.然后将处理程序绑定到该事件的元素: http://jsfiddle.net/H8ygx/
You can override the default append method and cause it to trigger a custom append event. Then bind a handler to an element for that event: http://jsfiddle.net/H8ygx/
(function($) {
var origAppend = $.fn.append;
$.fn.append = function () {
return origAppend.apply(this, arguments).trigger("append");
};
})(jQuery);
$("div").bind("append", function() { alert('Hello, world!'); });
$("div").append("<span>");
这篇关于在append()上做某事的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文