customtooltip.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. <p>This sample shows how to display another tooltip message on a valid textbox.</p>
  15. <div style="margin:20px 0;"></div>
  16. <div class="easyui-panel" title="Register" style="width:400px;padding:10px 60px 20px 60px">
  17. <table cellpadding="5">
  18. <tr>
  19. <td>User Name:</td>
  20. <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter User Name.',required:true,validType:'length[3,10]'"></td>
  21. </tr>
  22. <tr>
  23. <td>Email:</td>
  24. <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter a valid email.',required:true,validType:'email'"></td>
  25. </tr>
  26. <tr>
  27. <td>Birthday:</td>
  28. <td><input class="easyui-datebox"></td>
  29. </tr>
  30. <tr>
  31. <td>URL:</td>
  32. <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter your URL.',required:true,validType:'url'"></td>
  33. </tr>
  34. <tr>
  35. <td>Phone:</td>
  36. <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter your phone number.',required:true"></td>
  37. </tr>
  38. </table>
  39. </div>
  40. <style scoped="scoped">
  41. .textbox{
  42. height:20px;
  43. margin:0;
  44. padding:0 2px;
  45. box-sizing:content-box;
  46. }
  47. </style>
  48. <script>
  49. $(function(){
  50. $('input.easyui-validatebox').validatebox({
  51. tipOptions: { // the options to create tooltip
  52. showEvent: 'mouseenter',
  53. hideEvent: 'mouseleave',
  54. showDelay: 0,
  55. hideDelay: 0,
  56. zIndex: '',
  57. onShow: function(){
  58. if (!$(this).hasClass('validatebox-invalid')){
  59. if ($(this).tooltip('options').prompt){
  60. $(this).tooltip('update', $(this).tooltip('options').prompt);
  61. } else {
  62. $(this).tooltip('tip').hide();
  63. }
  64. } else {
  65. $(this).tooltip('tip').css({
  66. color: '#000',
  67. borderColor: '#CC9933',
  68. backgroundColor: '#FFFFCC'
  69. });
  70. }
  71. },
  72. onHide: function(){
  73. if (!$(this).tooltip('options').prompt){
  74. $(this).tooltip('destroy');
  75. }
  76. }
  77. }
  78. }).tooltip({
  79. position: 'right',
  80. content: function(){
  81. var opts = $(this).validatebox('options');
  82. return opts.prompt;
  83. },
  84. onShow: function(){
  85. $(this).tooltip('tip').css({
  86. color: '#000',
  87. borderColor: '#CC9933',
  88. backgroundColor: '#FFFFCC'
  89. });
  90. }
  91. });
  92. });
  93. </script>
  94. </body>
  95. </html>