1
0

jqueryValidation.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  6. <title>Ueditor在jquery validation下的验证</title>
  7. <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
  8. <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
  9. <script type="text/javascript" charset="utf-8" src="../ueditor.config.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="editor_api.js"></script>
  11. <script>
  12. $(function(){
  13. UE.getEditor('content');
  14. var validator = $("#myform").submit(function() {
  15. UE.getEditor('content').sync();
  16. }).validate({
  17. ignore: "",
  18. rules: {
  19. title: "required",
  20. content: "required"
  21. },
  22. errorPlacement: function(label, element) {
  23. label.insertAfter(element.is("textarea") ? element.next() : element);
  24. }
  25. });
  26. validator.focusInvalid = function() {
  27. if( this.settings.focusInvalid ) {
  28. try {
  29. var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
  30. if (toFocus.is("textarea")) {
  31. UE.getEditor('content').focus()
  32. } else {
  33. toFocus.filter(":visible").focus();
  34. }
  35. } catch(e) {
  36. }
  37. }
  38. }
  39. })
  40. </script>
  41. </head>
  42. <body>
  43. <form id="myform" action="">
  44. <h3>Ueditor在jquery validation下的验证</h3>
  45. <label>其他内容</label>
  46. <input name="title" />
  47. <br/>
  48. <label>编辑器</label>
  49. <textarea id="content" name="content" rows="15" cols="80" style="width: 80%"></textarea>
  50. <br />
  51. <input type="submit" name="save" value="Submit" />
  52. </form>
  53. </body>
  54. </html>