mik*_*eum 15 javascript jquery select focus
我无法理解为什么当textarea获得焦点时我无法获得textarea的内容.
请访问这里的实例:http://jsfiddle.net/mikkelbreum/aSvst/1
使用jQuery,这是我的代码.(在SAFARI中)它使得在单击事件的情况下选择文本,而不是焦点事件:
$('textarea.automarkup')
.mouseup(function(e){
    // fixes safari/chrome problem
    e.preventDefault();
})
.focus(function(e){
    $(this).select();
})
.click(function(e){
    $(this).select();
});
Tim*_*own 33
最简单的方法是将现有代码与计时器结合使用,因为focusWebKit中的事件通常太早:
jsFiddle示例:http://jsfiddle.net/NWaav/2/
码:
$('textarea.automarkup').focus(function() {
    var $this = $(this);
    $this.select();
    window.setTimeout(function() {
        $this.select();
    }, 1);
    // Work around WebKit's little problem
    function mouseUpHandler() {
        // Prevent further mouseup intervention
        $this.off("mouseup", mouseUpHandler);
        return false;
    }
    $this.mouseup(mouseUpHandler);
});
| 归档时间: | 
 | 
| 查看次数: | 19078 次 | 
| 最近记录: |