jump.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /** 跳转的代码 **/
  2. var oldContent= $("#head").attr("content");
  3. var content="width=device-width, initial-scale=1,maximum-scale=10,minimum-scale=0.1,user-scalable=no";
  4. var pageCount = parseInt($(".get_page_count").html());
  5. var Page = parseInt($(".get_page").html());
  6. var PageInfo = $(".get_page_info").html();
  7. var error = ['已经是第一页了', '已经是最后一页了', '跳转页数超出的范围', '已经在当前页了无需跳转'];
  8. var jump_interface_page='<div class="jump-interface jump-interface-page none">\n' +
  9. ' <div class="jump-box">' +
  10. ' <ul>' +
  11. ' <li class="tip">跳转</li>' +
  12. ' <li>' +
  13. PageInfo+
  14. ' </li>' +
  15. ' <li>将跳转到' +
  16. ' <input class="jumpNumber" id="jumpNumber" type="text"' +
  17. ' value="1" onkeyup="checkLen2(this)" oninput="value=value.replace(/[^\\d]/g,\'\')">' +
  18. ' </li>' +
  19. ' <li class="jump-save-box">' +
  20. ' <button class="jump" id="jump">跳转</button>' +
  21. ' <button class="cancel" id="cancel">取消</button>' +
  22. ' </li>' +
  23. ' </ul>' +
  24. ' </div>' +
  25. '</div>';
  26. var jump_interface_error='<div class="jump-interface jump-interface-error none">' +
  27. ' <div class="jump-box">' +
  28. ' <ul>' +
  29. ' <li class="tip">错误提示</li>' +
  30. ' <li class="tip-content">' +
  31. ' <div id="tip-content-div"></div>' +
  32. ' </li>' +
  33. ' <li class="jump-save-box">' +
  34. ' <button class="jump" id="esure">确定</button>' +
  35. ' <button class="cancel" id="esure-cancel">取消</button>' +
  36. ' </li>' +
  37. ' </ul>' +
  38. ' </div>' +
  39. '</div>';
  40. $("body").append(jump_interface_page);
  41. $("body").append(jump_interface_error);
  42. //上一页
  43. document.getElementById("prev_btn").onclick = function () {
  44. skip(0);
  45. };
  46. //下一页
  47. document.getElementById("next_btn").onclick = function () {
  48. skip(1);
  49. };
  50. //跳转功能代码
  51. function skip(type) {
  52. var jumpNumber = Page;
  53. var errorBool = false;
  54. if (type == 0) {
  55. Page = Page - 1;
  56. if (Page < 1) {
  57. errorBool = true;
  58. }
  59. } else if (type == 1) {
  60. Page = Page + 1;
  61. if (Page > pageCount) {
  62. errorBool = true;
  63. }
  64. } else {
  65. var PageValue = document.getElementById("jumpNumber").value;
  66. if (typeof PageValue == "undefined" || PageValue == null || PageValue == "") {
  67. errorBool = true;
  68. } else {
  69. Page = parseInt(PageValue);
  70. if (Page == null || Page < 1 || Page > pageCount) {
  71. errorBool = true;
  72. }
  73. if (jumpNumber == Page) {
  74. type = 3;
  75. errorBool = true;
  76. }
  77. }
  78. }
  79. if (errorBool) {
  80. Page = jumpNumber;
  81. document.getElementById("tip-content-div").innerHTML = error[type];
  82. $(".condition-box").addClass("none");
  83. $("#head").attr("content",content);
  84. $(".jump-interface-error").removeClass("none");
  85. } else {
  86. url = location.href; //把当前页面的地址赋给变量 url
  87. var times = url.split("&page");
  88. if (times.length < 2) {
  89. url += ("&page=" + Page);
  90. } else {
  91. url = times[0] + ("&page=" + Page);
  92. }
  93. self.location.replace(url); //刷新页面
  94. }
  95. }
  96. //自定义键盘
  97. var coolInput = new CoolInput({slt: '#jumpNumber'});
  98. //跳转界面
  99. document.getElementById("jump-phone-img").onclick = function () {
  100. $(".condition-box").addClass("none");
  101. $("#head").attr("content",content);
  102. $(".jump-interface-page").removeClass("none");
  103. coolInput.cursorT=$("#jumpNumber").offset().top;
  104. };
  105. //跳转
  106. document.getElementById("jump").onclick = function () {
  107. $(".jump-interface-page").addClass("none");
  108. $("#head").attr("content",oldContent);
  109. $(".condition-box").removeClass("none");
  110. skip(2);
  111. };
  112. document.getElementById("cancel").onclick = function () {
  113. $(".jump-interface-page").addClass("none");
  114. $("#head").attr("content",oldContent);
  115. $(".condition-box").removeClass("none");
  116. };
  117. document.getElementById("esure").onclick = function () {
  118. $(".jump-interface-error").addClass("none");
  119. $("#head").attr("content",oldContent);
  120. $(".condition-box").removeClass("none");
  121. };
  122. document.getElementById("esure-cancel").onclick = function () {
  123. $(".jump-interface-error").addClass("none");
  124. $("#head").attr("content",oldContent);
  125. $(".condition-box").removeClass("none");
  126. };