admin管理员组文章数量:1356368
I'm working with an existing system set up by someone else (no longer here). In this system, clicking on the text within a special <span>
will trigger a js function which will replace the text with an <input>
field. The text which was there is assigned as the value
of the <input>
element.
An onblur
event is assigned to this new <input>
field. This calls a function which updates the data in the database via an AJAX call. As part of this action, the <input>
field is replaced with the new value (same <span>
contents), and the onclick event is re-assigned. In this way, you can click on the text, change it, click elsewhere, and it is automatically updated in the database. Then you can do it again as it sets up the original events dynamically with each update.
It is in-between the first event and the second that I want access to that <input>
field. I want to add a jquery .datepicker()
to it.
How would I go about calling .datepicker()
on a dynamically-created element?
I'm working with an existing system set up by someone else (no longer here). In this system, clicking on the text within a special <span>
will trigger a js function which will replace the text with an <input>
field. The text which was there is assigned as the value
of the <input>
element.
An onblur
event is assigned to this new <input>
field. This calls a function which updates the data in the database via an AJAX call. As part of this action, the <input>
field is replaced with the new value (same <span>
contents), and the onclick event is re-assigned. In this way, you can click on the text, change it, click elsewhere, and it is automatically updated in the database. Then you can do it again as it sets up the original events dynamically with each update.
It is in-between the first event and the second that I want access to that <input>
field. I want to add a jquery .datepicker()
to it.
How would I go about calling .datepicker()
on a dynamically-created element?
-
2
Couldn't you just update the "js function which will replace the text with an
<input>
" to bind the datepicker as well? – mu is too short Commented Nov 8, 2011 at 3:07 - actual code would help also... – jondavidjohn Commented Nov 8, 2011 at 3:08
- @mu: it's being used all over, in many scripts, for all text input fields. but I only want to use it for one, so I don't want a calendar button after all those other input fields. makes things a bit more plicated. good idea, though. – user965641 Commented Nov 8, 2011 at 18:46
1 Answer
Reset to default 4No, there isn't an event similar to an onCreate. The closest you can find is jQuery's .live(). This allows you to bind an event to an element now or in the future. I also think it will probably solve your problem.
http://api.jquery./live/
$('input').live('click', function() {
$(this).datepicker();
});
As AutoSponge handily pointed out, live is deprecated as of jQuery 1.7. They suggest using on or delegate instead.
http://api.jquery./on/
http://api.jquery./delegate/
本文标签: jqueryIn JavaScriptis there such an event as onCreateStack Overflow
版权声明:本文标题:jquery - In JavaScript, is there such an event as onCreate? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744060925a2584108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论