2

这是代码:

$("#textyt:input").focus(function() {
 $(this).animate({width:"545px"},500).css("color","#614A3E");
 $(this).select();
 $(this).mouseup(function(e){
  e.preventDefault();
 });
});

如果我取消动画效果,则此焦点事件会选择文本(如我所愿)。使用动画效果,当动画在 Firefox 中完成时,文本会取消选择。这在 Safari 中运行良好。有什么方法可以确保动画在 FF 中结束时仍然选择文本?谢谢!

4

1 回答 1

3

尝试使用:

 this.focus();
 this.select();

动画之后。

这将在动画完成后选择文本。宽度动画通过动态更改 CSS 宽度属性来工作,并且可能会在 Firefox 中失去焦点,但更好的主意可能是更改容器元素的宽度,而不是实际的文本区域。

$("#textyt:input").focus(function() {
    $(this).animate(
        {width:"545px"}, 500, function(){
            this.focus();
            this.select();
        }).css("color","#614A3E");
     $(this).select();
     $(this).mouseup(function(e){
         e.preventDefault();
     });
});
于 2009-10-17T02:50:09.390 回答