errorplacement.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Error Placement in ValidateBox - 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>Error Placement in ValidateBox</h2>
  14. <p>This example shows how to display the error message below the field.</p>
  15. <div style="margin:20px 0;"></div>
  16. <div class="easyui-panel" title="Register" style="width:100%;max-width:400px;padding:30px 60px;">
  17. <div style="margin-bottom:20px">
  18. <label for="username" class="label-top">User Name:</label>
  19. <input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'length[3,10]',validateOnCreate:true,err:err">
  20. </div>
  21. <div style="margin-bottom:20px">
  22. <label for="email" class="label-top">Email:</label>
  23. <input id="email" class="easyui-validatebox tb" data-options="required:true,validType:'email',validateOnCreate:false,err:err">
  24. </div>
  25. <div style="margin-bottom:20px">
  26. <label for="url" class="label-top">Url:</label>
  27. <input id="url" class="easyui-validatebox tb" data-options="required:true,validType:'url',validateOnCreate:false,err:err">
  28. </div>
  29. <div style="margin-bottom:20px">
  30. <label for="phone" class="label-top">Phone:</label>
  31. <input id="phone" class="easyui-validatebox tb" data-options="required:true,validateOnCreate:false,err:err">
  32. </div>
  33. </div>
  34. <style scoped="scoped">
  35. .tb{
  36. width:100%;
  37. margin:0;
  38. padding:5px 4px;
  39. border:1px solid #ccc;
  40. box-sizing:border-box;
  41. }
  42. .error-message{
  43. margin: 4px 0 0 0;
  44. padding: 0;
  45. color: red;
  46. }
  47. </style>
  48. <script type="text/javascript">
  49. function err(target, message){
  50. var t = $(target);
  51. if (t.hasClass('textbox-text')){
  52. t = t.parent();
  53. }
  54. var m = t.next('.error-message');
  55. if (!m.length){
  56. m = $('<div class="error-message"></div>').insertAfter(t);
  57. }
  58. m.html(message);
  59. }
  60. </script>
  61. </body>
  62. </html>