scHintBox.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!----------------------------------------------------------------------------------------------------------------------
  2. chenshilong, 2018-04-29
  3. 自定义对话框,通用,用于替代系统对话框。系统自带的比较简陋,最严重的是一旦被浏览器屏蔽则无法再弹出。
  4. 自定义对话框包括:
  5. 1、只有一个按钮的信息提示框。
  6. 2、有两个按钮的操作确认询问框。
  7. 3、有三个按钮的多分支选择询问框。
  8. 4、输入文本值对话框。
  9. ----------------------------------------------------------------------------------------------------------------------->
  10. <div class="modal fade" id="hintBox" data-backdrop="static">
  11. <div class="modal-dialog" role="document">
  12. <div class="modal-content">
  13. <div class="modal-header">
  14. <h5 class="modal-title" id="hintBox_title">标题</h5>
  15. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  16. <span aria-hidden="true">&times;</span>
  17. </button>
  18. </div>
  19. <div class="modal-body">
  20. <div id = "hintBox_info" style="margin:5px 10px 10px 10px;">提示明细</div>
  21. <div style="margin:5px 10px 5px 10px;">
  22. <input type="text" class="form-control" value="" id="hintBox_value"/>
  23. </div>
  24. </div>
  25. <div class="modal-footer" style="justify-content: right">
  26. <button type="button" class="btn btn-primary" data-dismiss="modal" id="hintBox_btn_yes">是</button>
  27. <button type="button" class="btn btn-primary" data-dismiss="modal" id="hintBox_btn_no">否</button>
  28. <button type="button" class="btn btn-secondary" data-dismiss="modal" id="hintBox_btn_cancel">取消</button>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <script>
  34. G_HINTBOX_VALUE = null;
  35. hintBoxButtonType = {yes: 1, yesNo: 2, yesNoCancel: 3};
  36. function speFont(str){
  37. return `<span style='color:red;font-weight:bold;font-size:15px'> ${str} </span>`;
  38. };
  39. function hintBox(title, caption, btnType, doYes, doNo) {
  40. $('#hintBox_title').text(title);
  41. $('#hintBox_info').html(caption);
  42. $('#hintBox_value').hide();
  43. $('#hintBox_info').show();
  44. $('#hintBox_btn_yes').show();
  45. $('#hintBox_btn_yes').text('是');
  46. $("#hintBox_btn_yes").unbind();
  47. $('#hintBox_btn_no').show();
  48. $('#hintBox_btn_no').text('否');
  49. $('#hintBox_btn_no').unbind();
  50. $('#hintBox_btn_cancel').show();
  51. $('#hintBox_btn_cancel').text('取消');
  52. $('#hintBox_btn_cancel').unbind();
  53. switch (btnType) {
  54. case hintBoxButtonType.yes:
  55. $('#hintBox_btn_yes').text('确定');
  56. $('#hintBox_btn_no').hide();
  57. $('#hintBox_btn_cancel').hide();
  58. break;
  59. case hintBoxButtonType.yesNo:
  60. $('#hintBox_btn_cancel').hide();
  61. break;
  62. }
  63. if (doYes){
  64. $('#hintBox_btn_yes').click(doYes);
  65. }
  66. if (doNo){
  67. $('#hintBox_btn_no').click(doNo);
  68. }
  69. $('#hintBox_btn_cancel').click(
  70. function () {return;}
  71. );
  72. $("#hintBox").modal({show:true});
  73. };
  74. function hintBoxValue(title, value, doYes) {
  75. $('#hintBox_title').text(title);
  76. $('#hintBox_info').hide();
  77. G_HINTBOX_VALUE = value;
  78. $('#hintBox_value').show();
  79. $('#hintBox_value').val(value);
  80. $("#hintBox_value").unbind();
  81. $("#hintBox_value").change(
  82. function () {
  83. G_HINTBOX_VALUE = $('#hintBox_value').val();
  84. }
  85. );
  86. $('#hintBox_btn_yes').show();
  87. $('#hintBox_btn_yes').text('确定');
  88. $('#hintBox_btn_yes').unbind();
  89. $('#hintBox_btn_yes').click(doYes); // doYes不能给参数
  90. $('#hintBox_btn_no').hide();
  91. $('#hintBox_btn_cancel').hide();
  92. $("#hintBox").modal({show:true});
  93. };
  94. </script>