在对象创建时触发javascript事件 [英] fire javascript event on object creation
问题描述
我有一个< div>
editableContent =true
,当用户按下< div>
,创建一个新的< div>
,仅占用该行。在我原来的< div>
中创建< div>
对象时,可能会触发事件对象? 我知道这样做的一种方法是听击键和按下输入键,做一些逻辑来弄清楚该做什么,但这似乎不那么优雅 - 所以如果有另一种方式,这将是很棒的。
谢谢!
有一堆 DOM Events ,其中一些将由firefox支持例如。但我不认为IE将只支持其中之一。 这里是一个完整的列表。
首先你可以在每次创建一个新的div时触发一个自定义事件,或者你有一个settimeout来检查你的div子节点的数量是否改变。
Is there any way to fire an event when an object of a certain type is created?
I have an <div>
element with editableContent="true"
and when the user presses enter within the <div>
, a new <div>
is created that takes up just that line. Is it possible to have an event fire whenever a <div>
object is created within my original <div>
object?
I know one way to do this would to listen for keystrokes and on an 'enter' key being pressed, do a bunch of logic to figure out what to do, but this seems a lot less elegant - so it would be great if there was another way.
Thanks!
There are the a bunch of DOM Events and some of them will be supported by firefox for example. But I dont think that IE will support only one of them. Here is a complete list. First you can fire a custom event every time you create a new div, or you have a settimeout that checks every second if the count of you divs childnodes has changed.
这篇关于在对象创建时触发javascript事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!