English 中文(简体)
作出要素的分类活动
原标题:jquery event for on render an element

I am trying to do all dom manipulations off screen and then make it visible. Which works, except now I have the situation where I am trying to do it with a form which I want to focus on the first input text upon rendering it on the browser.

Something like: myForm.prependTo(myDiv).show().find( input:first ).focus();

Problem is that the focus is being called before the form has finished rendering which is causing the lovely error Can t move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus

How do other web developers handle the similiar situation of manipulating elements off screen and then making it visible? I wish jQuery had something like
myForm.prependTo(myDiv, function() { /* on render code here */ })

I know one way of doing it is setting a timeout and when it fires I put focus on the input, but I feel like that s not really the cleanest way to do things. I know the iframe has an onload event, so I m curious if people usually draw their elements in some hidden iframe and listen for its load event to know when the element has finished rendering? If so could you point me to an example of doing this?

最佳回答
myForm.prependTo(myDiv).show(function(e){
    $(this).find( input:first ).focus();
});​
问题回答

我知道我7年晚了,但我也有一个类似的问题,我解决了这个问题,因为,在我任满的手之后,我需要做些什么。

我有恢复功能,但零或接近零的直观反馈是该要素已经恢复的。

我首先试图空出这个要素。 它仍在发挥作用,但至今仍然有零的直观反馈。

$("#someSelector").empty(); restore();

之后,我发现(......)在行为发生后发生;因此,我把它变成了类似的东西。

$("#someSelector").empty().ready(function() { restore(); });

如今,恢复工作直到采取空洞的行动之后才会发生。 这意味着我的内容PREARS空洞,然后重新填满(总是这样做,但现在用户可以看到这种情况发生)。

我几天前就找到了这一解决办法,认为这是一个不同的问题,我可以记住一些模糊的搜索。 然后,我需要再次发言,但不能完全记住我所做的事。 现在,我的搜索包括“jquery”和“render”等词,并带领我来到这里。

我最后看看着我的守则,以找出我所做的事情。 我认为,如果其他人在这一岗位上umble卑,并且实际上需要执行某些使事情发生的话,那么,把它放在这里也许是一个好的想法。

乘客。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签