Two methods: 1. Use css() to set the cursor color style, the syntax is "element.css("caret-color","transparent")"; 2. Use attr(), the syntax is "element. attr("style","caret-color:transparent")".
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.
In HTML, you can make the cursor disappear by setting the cursor color to transparent, that is, adding the caret-color:transparent;
style;
The following introduces jquery settings for transparency Two methods of cursor.
Method 1: Use css() to directly set the caret-color attribute
The css() method sets or returns one or more style attributes of the selected element.
Just set the value of the caret-color attribute to transparent.
元素对象.css("caret-color","transparent");
Example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-3.2.1.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("input").css("caret-color","transparent"); }); }); </script> </head> <body> <input type="text" /><br><br> <button>让光标消失</button> </body> </html>
2. Use attr() to set the style attribute and add caret-color:transparent; style
attr() can set element attributes.
Just set the style attribute and add caret-color:transparent; inline style.
Example:
$(document).ready(function() { $("button").click(function() { $("input").attr("style","caret-color:transparent"); }); });
[Recommended learning: jQuery video tutorial, web front-end video]
The above is the detailed content of How to make the cursor disappear with jquery. For more information, please follow other related articles on the PHP Chinese website!