jquery 如何在输入文本中隐藏闪烁光标?

nwo49xxi  于 2022-11-22  发布在  jQuery
关注(0)|答案(7)|浏览(210)

我 想 做 一些 看 起来 像 选择 输入 但 实际 上 不是 的 东西 , 下面 是 步骤 。
我 做 了 一 个 <input type="text">
我 添加 了 一 个 background-image , 它 将 显示 一 个 " 选择 箭头 " , 给 人 一 种 它 是 一 个 选择 框 的 印象 。
我 向 此 输入 添加 了 一 个 默认 值 。
当 我 点击 它 的 时候 , 会 有 一 个 隐藏 的 div , 它 会 在 这个 输入 的 正 下方 。
我 尝试 了 只 读 的 东西 , 使 值 不 能 改变 , 但 闪烁 的 光标 将 显示 出来 。
如果 我 使用 disabled , 闪烁 的 光标 将 不会 出现 , 但是 jQuery 中 的 .click().focus 函数 将 不 起 作用 。 下拉 菜单 将 不会 显示 SlideDown()
如何 使 其 可 单击 , 同时 不 显示 闪烁 的 光标 ?
这 是 密码

<div style="padding-top:17px; overflow:hidden;">
    <div style="float:left;">
        <label for="secretquestion">Secret Question</label><br>
        <input type="text" class="inputselect" id="secretquestion" name="secretquestion" value="Choose a Secret Question" tabindex=10 /><br>
        <div class="selectoptions" id="secretquestionoptions">
            <b>test</b>
        </div> 
    </div>
</div>

中 的 每 一 个
CSS 系统

.selectoptions
{
    display: none;
    background-color: white;  
    color: rgb(46,97,158); 
    width: 250px; 
    margin:auto; 
    border-style: solid; 
    border-width:1px; 
    border-color: rgb(46,97,158);  
    font-size: 14px; 
    text-align: center; 
}

.inputselect {
    color: white;  
    cursor: pointer;  
    background-image: url('inputselect.png');
    padding-top: 5px; 
    padding-bottom: 5px;   
    padding-left:10px; 
    padding-right:-10px;
    width:240px; 
    border-style: solid; 
    border-color: rgb(46,97,158); 
    border-width: 1px;
} 
.inputselect:hover {
    outline:none;      
    color:aqua; 
    cursor: pointer; 
    background-image: url('inputselecthover.png');
}
.inputselect:focus {
    outline:none;      
    color:aqua; 
    cursor: pointer; 
    background-image: url('inputselecthover.png');
}

格式

fnx2tebb

fnx2tebb1#

只需将以下代码添加到“inputselect”类:

caret-color: transparent;
q1qsirdb

q1qsirdb2#

光标 的 颜色 与 文本 的 颜色 相 匹配 。

<input type="text" style="color: transparent">

中 的 每 一 个
如果 你 真 的 想 在 输入 框 中 显示 文本 ( 我 的 , 有些 人 是 有 需要 的 ) , 你 可以 使用 文本 阴影 。

<style>
    body, div, input {
       color: #afa;
       text-shadow: 0px 0px 1px #fff;
    }
<style>

格式
( 已 测试 Firefox 和 Safari ) 。

06odsfpq

06odsfpq3#

我只是用了一个模糊来摆脱光标。

$('input').mousedown(function(e){
  e.preventDefault();
  $(this).blur();
  return false;
});
cu6pst1q

cu6pst1q4#

我认为这是一个完美的解决方案:使输入足够宽,右对齐屏幕右,从而使光标和内容位于屏幕外部,而它仍然是可点击的

d8tt03nd

d8tt03nd5#

我终于找到了一个妙计。

<div class="wrapper">
    <input type="text" />
</div>

.wrappr {
    width: 100px;
    height: 30px;
    overflow: hidden;
}
.wrapper input {
    width: 120px;
    height: 30px;
    margin-left: -20px;
    text-align: left;
}

而且在我的座位上,它起作用了!

yrdbyhpb

yrdbyhpb6#

这可能会有帮助(虽然不是完整的回复)-我在最近的一个项目中用它来禁用输入:

document.getElementById('Object').readOnly = true;
    document.getElementById('Object').style.backgroundColor = '#e6e6e6';
    document.getElementById('Object').onfocus = function(){
        document.getElementById('Object').blur();
    };

当用户点击输入时,焦点会聚焦在输入上,blur()函数会移除焦点。在这两者之间,将readOnly设置为“True”和将背景颜色设置为灰色(#e6e6e6),用户应该不会感到困惑。

vsdwdz23

vsdwdz237#

试试这个代码,它对我工作:-

<div class="input-parent" style="margin-left: 30px;">
     <input type="text" />
</div>

input-parent {
    width: 100px;
    height: 30px;
    overflow: hidden;
    }
.input-parent input {
    width: 120px;
    height: 30px;
    margin-left: -20px;
    text-align: left;
    caret-color: transparent;
    }

相关问题