You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

3 days ago
  1. function postForm(formId, url, funcSuccess){
  2. var postData = {};
  3. var validate = [];
  4. $("#"+formId+" input").each(function(index){
  5. var val = $(this).val();
  6. if (val == ""){
  7. validate.push("["+$(this).attr("placeholder")+"]不能为空!");
  8. }
  9. postData[$(this).attr("name")] = val;
  10. });
  11. if(validate.length > 0){
  12. $.messager.alert("Warning", validate.join("<br />"), "warning");
  13. return;
  14. }
  15. $.messager.confirm("Confirm","Submit", function(cr){
  16. if (cr){
  17. $.post(url, postData, function(ret){
  18. if (ret.success){
  19. if(funcSuccess){
  20. funcSuccess(ret);
  21. } else {
  22. $("#app").html("<p class='op-success'>Successfully</p>");
  23. }
  24. }else{
  25. $.messager.alert("Error", ret.errorMsg, "error");
  26. }
  27. })
  28. }
  29. })
  30. }
  31. $(".for-scan").on("focus", "input", function() {
  32. $(this).css("text-transform", "uppercase");
  33. });
  34. $(".for-scan").on("blur", "input", function() {
  35. $(this).val($(this).val().trim().toUpperCase());
  36. });
  37. $(".for-scan").on("keydown", "input", function(){
  38. console.log(event.keyCode);
  39. if (event.keyCode >= 97 && event.keyCode <= 122){
  40. event.keyCode = event.keyCode - 32;
  41. }
  42. if(event.keyCode==13) {
  43. event.keyCode = 9;
  44. var inputs = $(".for-scan").find(":input:visible:not(:disabled):not([readonly])");
  45. console.log(inputs);
  46. var idx = inputs.index(this);
  47. if (idx == inputs.length - 1) {
  48. idx = -1;
  49. } else {
  50. inputs[idx + 1].focus(); // handles submit buttons
  51. }
  52. try {
  53. inputs[idx + 1].select();
  54. }
  55. catch (err) {
  56. // handle objects not offering select
  57. }
  58. return false;
  59. }
  60. });
  61. function showEl(id, b){
  62. if (b) {
  63. $(id).show();
  64. } else {
  65. $(id).hide();
  66. }
  67. }
  68. function enableEl(id, b){
  69. $(id).prop('disabled', !b);
  70. }