customtooltip.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Custom ValidateBox Tooltip - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Custom ValidateBox Tooltip</h2>
  14. <div class="demo-info">
  15. <div class="demo-tip icon-tip"></div>
  16. <div>This sample shows how to display another tooltip message on a valid textbox.</div>
  17. </div>
  18. <div style="margin:10px 0;"></div>
  19. <div class="easyui-panel" title="Register" style="width:400px;padding:10px">
  20. <table>
  21. <tr>
  22. <td>User Name:</td>
  23. <td><input class="easyui-validatebox" data-options="prompt:'Enter User Name.',required:true,validType:'length[3,10]'"></td>
  24. </tr>
  25. <tr>
  26. <td>Email:</td>
  27. <td><input class="easyui-validatebox" data-options="prompt:'Enter a valid email.',required:true,validType:'email'"></td>
  28. </tr>
  29. <tr>
  30. <td>Birthday:</td>
  31. <td><input class="easyui-datebox"></td>
  32. </tr>
  33. <tr>
  34. <td>URL:</td>
  35. <td><input class="easyui-validatebox" data-options="prompt:'Enter your URL.',required:true,validType:'url'"></td>
  36. </tr>
  37. <tr>
  38. <td>Phone:</td>
  39. <td><input class="easyui-validatebox" data-options="prompt:'Enter your phone number.',required:true"></td>
  40. </tr>
  41. </table>
  42. </div>
  43. <script>
  44. $(function(){
  45. $('input.easyui-validatebox').validatebox({
  46. tipOptions: { // the options to create tooltip
  47. showEvent: 'mouseenter',
  48. hideEvent: 'mouseleave',
  49. showDelay: 0,
  50. hideDelay: 0,
  51. zIndex: '',
  52. onShow: function(){
  53. if (!$(this).hasClass('validatebox-invalid')){
  54. if ($(this).tooltip('options').prompt){
  55. $(this).tooltip('update', $(this).tooltip('options').prompt);
  56. } else {
  57. $(this).tooltip('tip').hide();
  58. }
  59. } else {
  60. $(this).tooltip('tip').css({
  61. color: '#000',
  62. borderColor: '#CC9933',
  63. backgroundColor: '#FFFFCC'
  64. });
  65. }
  66. },
  67. onHide: function(){
  68. if (!$(this).tooltip('options').prompt){
  69. $(this).tooltip('destroy');
  70. }
  71. }
  72. }
  73. }).tooltip({
  74. position: 'right',
  75. content: function(){
  76. var opts = $(this).validatebox('options');
  77. return opts.prompt;
  78. },
  79. onShow: function(){
  80. $(this).tooltip('tip').css({
  81. color: '#000',
  82. borderColor: '#CC9933',
  83. backgroundColor: '#FFFFCC'
  84. });
  85. }
  86. });
  87. });
  88. </script>
  89. </body>
  90. </html>