工具提示框(Tooltip) - 表单
使用下面的按钮来显示帮助文本,或者只需要让鼠标悬停在输入框上或者让输入框获得焦点,即可显示相应输入框的帮助文本。
在 CSS 中定义一个固定的宽度,让同时显示所有的帮助文本时看起来更一致。
源代码
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI 工具提示框(Tooltip) - 表单</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css"> <style> label { display: inline-block; width: 5em; } fieldset div { margin-bottom: 2em; } fieldset .help { display: inline-block; } .ui-tooltip { width: 210px; } </style> <script> $(function() { var tooltips = $( "[title]" ).tooltip(); $( "<button>" ) .text( "Show help" ) .button() .click(function() { tooltips.tooltip( "open" ); }) .insertAfter( "form" ); }); </script> </head> <body> <form> <fieldset> <div> <label for="firstname">名字</label> <input id="firstname" name="firstname" title="请提供您的名字。"> </div> <div> <label for="lastname">姓氏</label> <input id="lastname" name="lastname" title="请提供您的姓氏。"> </div> <div> <label for="address">地址</label> <input id="address" name="address" title="您的家庭或工作地址。"> </div> </fieldset> </form> </body> </html>