注重与jQuery加载元 [英] Focus loaded element with jQuery

查看:104
本文介绍了注重与jQuery加载元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要替换jQuery的负荷方法的HTML元素,并希望加载的元素中集中输入元素与类 .focus 。这可能是有与类 .focus 一个以上的元素,因此被加载元件内选择是很重要的。

I want to replace a html element with jQuery's load method and want to focus an input element within the loaded elements with the class .focus. It is possible that there is more than one element with the class .focus, so it is important to select within the loaded element.

我尝试以下,但它不工作:

I tried the following but it doesn't work:

  paragraphToBeReplaced.load(
    "/some/url", 
    function(event) { event.data.contents(".focus").focus(); }
  );

我如何将焦点设置到装载的元素?我使用jQuery 1.7.1。

How can I set the focus to a loaded element? I'm using jQuery 1.7.1.

推荐答案

在负载回调是新的内容被加载到的元素。使用find()可在此元素中寻找你的类

Within the load callback this is the element that new content is being loaded into. Using find() can search within this element for your class

paragraphToBeReplaced.load( "/some/url",    function() { 
         $(this).find(".focus").focus();
});

这篇关于注重与jQuery加载元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆