最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove text cursor to input with Jquery - Stack Overflow

programmeradmin1浏览0评论

when I do focus on an input

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

in the input appears the text cursor... and the only way to remove it (so like the input it not focus) is to click in another part of document...

with jquery how i can remove the text cursor ?

i tried this:

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

but this remove listener not text cursor

thanks!

when I do focus on an input

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

in the input appears the text cursor... and the only way to remove it (so like the input it not focus) is to click in another part of document...

with jquery how i can remove the text cursor ?

i tried this:

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

but this remove listener not text cursor

thanks!

Share Improve this question asked Nov 28, 2015 at 18:50 BorjaBorja 3,5797 gold badges38 silver badges75 bronze badges 1
  • 2 Should the user still be able to type when removing the cursor? – Jacques Marais Commented Nov 28, 2015 at 18:55
Add a ment  | 

2 Answers 2

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

This code disables the focus. But it's better if you make a disabled input.

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

You can do it easily with css like the code below.

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

Hope this will help you.

发布评论

评论列表(0)

  1. 暂无评论