我试图在我的textarea(#texttype)中完全禁用鼠标,但是当你单击包装器(#line)时,它会将光标移动到textarea中写入的内容的末尾。下面的代码几乎可以工作但是一旦取消选择textarea,单击包装器不会将光标放回到最后,就像文本区域被锁定所以用户不能再输入...
HTML:
<div id ="line">
<textarea wrap="off" draggable="false" id="texttype" name="texttype" spellcheck="false" class="type" onkeyup="countChar(this)" onkeypress="keypressed(e)"></textarea>
</div>
JS:
var toggle_mouse = $('#line').mousedown(function(event){
$('#texttype').focus(function(){
this.selectionStart = this.selectionEnd = this.value.length;
});
});
var mouse_off = $('#texttype').mousedown(function(event){
event.preventDefault();
});
答案 0 :(得分:0)
试试这段代码:
var mouse_off = $('#texttype').mousedown(function (event) {
event.preventDefault();
})
.focus(function () {
this.selectionStart = this.selectionEnd = this.value.length;
});
var toggle_mouse = $('#line').mousedown(function (event) {
mouse_off.focus();
});
你的错误是你试图在mousedown事件处理程序中绑定textarea焦点事件。你不应该这样做。
答案 1 :(得分:0)
不确定这会起作用 - 但可能使文字无法选择而不是禁用鼠标?
#textarea a {
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}