2013-10-06 67 views
1

是否可以右鍵點擊textarea來選擇文本並同時彈出選項對話框?如何用鼠標右鍵點擊選擇textarea中的文字

我想消除左擊的額外單擊以選中所有文本,然後右鍵單擊在

<textarea onclick="this.focus();this.select()" readonly="readonly"> 
example text 
</textarea> 
+0

爲什麼不在用戶點擊後選擇所有文本和副本到剪貼板的上下文菜單中提供'copyAll'選項? – Jivings

回答

3

,選擇「複製」只是使用替代的onclick oncontextmenu ..

+0

完美。謝謝 – grabury

+0

沒問題..很高興我能幫到 –

1

oncontextmenu是您正在尋找的活動。

<textarea oncontextmenu="this.focus();this.select()" readonly="readonly"> 
example text 
</textarea> 

參考http://jsfiddle.net/EyNWz/

希望它幫助。

0

使用oncontextmenu事件如本例:

<div oncontextmenu="this.focus();this.select();return false;" readonly="readonly"> 
    example text 
</div> 

使用「返回false」,如果你不想要的標準上下文菜單彈出,以防萬一你改變主意。

+0

他想要右鍵菜單 – Archer

0

只是一種不同的方式來實現JQuery的右鍵單擊。

event.which == 3表示右鍵單擊。

$('textarea').mousedown(function(event) { 
if(event.which == 3){ 
    var THIS = $(this); 
    THIS.focus(); 
    THIS.select(); 
    } 
}); 
相關問題