在 jQuery 中悬停文本框时显示工具提示文本
jqueryweb developmentfront end technology更新于 2026/1/6 4:37:17
为此,请使用 jQuery(selector).toolTip()。
示例
以下是代码: −
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<label>Write Your Favourite Subject Name:</label>
<input id="demoTooltip" title="Your Favourite Subject may be JavaScript...">
</body>
<script>
jQuery(".demoTooltip").toolTip()
</script>
</html>
要运行上述程序,请将文件名保存为 anyName.html (index.html)。右键单击该文件,然后在 VS Code 编辑器中选择"使用实时服务器打开"选项。
输出
输出如下 −

将鼠标悬停在文本框内时,您将看到工具提示 −
Your Favourite Subject may be JavaScript...
也显示在下面的屏幕截图中 −


