Raj*_*i.J 2 html javascript css jquery
我有一个文本字段(全名),单击"设置焦点"按钮,我希望在文本字段(全名)上设置焦点,但不希望在聚焦文本字段中闪烁光标.如何使用js/jQuery实现这一目标.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Customer Details</title>
</head>
<body>
<input type="text" id="fullname" placeholder="Name">
<button type="button" onClick="document.getElementById('fullname').focus()" id="button">Set Focus</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我尝试过使用jquery和js focus().但在这两种情况下,我都可以看到聚焦文本域中闪烁的光标.我看到了一个解决方案,要求我改变文本阴影,边框和轮廓来实现这一目标.但我想保留重点文本字段的边框和轮廓
这个技巧似乎适用于所有主流浏览器,保持大纲\边框和隐藏闪烁插入符:
#fullname:focus{
text-indent: -9999em;
text-shadow : 9999em 0 0 #000;
}Run Code Online (Sandbox Code Playgroud)
<input type="text" id="fullname" placeholder="Name" />
<button type="button" onClick="document.getElementById('fullname').focus()" id="button">Set Focus</button>Run Code Online (Sandbox Code Playgroud)