代码之家  ›  专栏  ›  技术社区  ›  Mike Webb

jQuery等价于原型函数.activate()

  •  6
  • Mike Webb  · 技术社区  · 15 年前

    原型的 activate

    根据原型网站。即

    $('my_element_id').activate();
    

    jQuery中的等价函数是什么?

    4 回复  |  直到 14 年前
        1
  •  5
  •   jAndy    15 年前
    $('#my_element_id').focus();
    

    这是一条捷径

    $('#my_element_id').trigger('focus');
    

    http://api.jquery.com/focus/

        2
  •  4
  •   edwines    14 年前

    Prototype的activate()函数关注并选择表单元素的全部内容。

    在JQuery中,可以使用三个函数复制此行为:

    // Focus
    $('my_element_id').focus();
    
    // Focus and select the content.
    $('my_element_id').focus().select();
    
    // Focus and select the content without problems in Google chrome
    $('my_element_id').focus().select().mouseup(function(event){
      event.preventDefault();
    });
    
        3
  •  2
  •   Dave Swersky    15 年前
    $('my_element_id').focus();
    
        4
  •  1
  •   acme    14 年前

    focus() 方法不选择输入字段中的文本。相反,添加 select() :

    $('my_element_id').focus().select();