删除要使用Jquery输入的文本光标

Remove text cursor to input with Jquery

本文关键字:文本 光标 输入 Jquery 删除      更新时间:2023-09-26

当我关注输入时

$('#bar input').focus(function(){
// code code
});

在输入中出现文本光标。。。删除它的唯一方法(就像输入一样,它不是焦点)是点击文档的另一部分。。。

使用jquery如何删除文本光标?

我试过这个:

$('#bar input').off('focus'); 

但这删除了监听器而不是文本光标

谢谢!

$('#bar input').on('focus', function(e) { 
    e.preventDefault();
    $(this).blur();
}

此代码禁用焦点。但如果您进行禁用输入,效果会更好。

<input disabled="disabled" type="text">

您可以像下面的代码一样轻松地使用css。

#bar input{
    color : transparent;
    text-shadow : 0 0 0 #000;
}
#bar input:focus{
    outline : none;
}
<div id="bar">
     <input type="text"/>    
</div>

希望这对你有帮助。