index.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>address-parse</title>
  6. <script src="js/bundle.js?v=1.2.11"></script>
  7. </head>
  8. <body>
  9. <h1>address parse 地址解析测试</h1>
  10. <div class="input">
  11. <textarea autocomplete="off" rows="3" placeholder="请输入地址" class="input__inner" id="input"></textarea>
  12. <div style="margin-left: 15px">
  13. <button class="parse__button" id="button">解析</button>
  14. <input type="checkbox" checked="checked" id="parseAll"> parseAll
  15. </div>
  16. </div>
  17. <div class="result">
  18. <div class="result__label">解析地址</div>
  19. <div class="result__value" id="address"></div>
  20. </div>
  21. <div class="result">
  22. <div class="result__label">解析结果</div>
  23. <div class="result__value">
  24. <pre><code id="result"></code></pre>
  25. </div>
  26. </div>
  27. <div class="result">
  28. <div class="result__label">全部结果</div>
  29. <div class="result__value">
  30. <pre><code id="resultAll"></code></pre>
  31. </div>
  32. </div>
  33. <script>
  34. document.getElementById('button').addEventListener('click', parse);
  35. window.onload = function () {
  36. var address = GetQueryValue('address');
  37. if (address) {
  38. document.getElementById('input').value = address;
  39. parse();
  40. }
  41. };
  42. function parse() {
  43. var address = document.getElementById('input').value;
  44. var parseAll = document.getElementById('parseAll').checked;
  45. var results = AddressParse.parse(address, parseAll);
  46. document.getElementById('address').innerHTML = address;
  47. document.getElementById('result').innerHTML = JSON.stringify(results[0] || {}, null, 2);
  48. document.getElementById('resultAll').innerHTML = JSON.stringify(results, null, 2);
  49. }
  50. function GetQueryValue(queryName) {
  51. var query = decodeURI(window.location.search.substring(1));
  52. var vars = query.split('&');
  53. for (var i = 0; i < vars.length; i++) {
  54. var pair = vars[i].split('=');
  55. if (pair[0] === queryName) {
  56. return pair[1];
  57. }
  58. }
  59. return '';
  60. }
  61. </script>
  62. </body>
  63. <style>
  64. * {
  65. font-family: Open Sans, Helvetica Neue, Microsoft YaHei, Helvetica, Arial, sans-serif;
  66. font-size: 14px;
  67. }
  68. .result {
  69. margin-top: 15px;
  70. display: flex;
  71. width: 700px;
  72. }
  73. .result__label {
  74. width: 80px;
  75. color: #606266;
  76. }
  77. .result__value {
  78. flex: 1;
  79. color: #333;
  80. }
  81. .input {
  82. flex: 1;
  83. display: flex;
  84. }
  85. .input__inner {
  86. min-height: 33px;
  87. display: block;
  88. resize: vertical;
  89. padding: 5px 15px;
  90. line-height: 1.5;
  91. box-sizing: border-box;
  92. font-size: inherit;
  93. color: #606266;
  94. background-color: #fff;
  95. background-image: none;
  96. border: 1px solid #dcdfe6;
  97. border-radius: 4px;
  98. transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  99. width: 700px;
  100. }
  101. .input__inner:focus, .parse__button:focus {
  102. outline: 0;
  103. border-color: #409eff;
  104. box-shadow: 0 0 0 2px rgba(24, 144, 255, .2);
  105. }
  106. .parse__button {
  107. display: inline-block;
  108. line-height: 1;
  109. white-space: nowrap;
  110. cursor: pointer;
  111. -webkit-appearance: none;
  112. text-align: center;
  113. -webkit-box-sizing: border-box;
  114. box-sizing: border-box;
  115. outline: 0;
  116. margin: 0;
  117. -webkit-transition: .1s;
  118. transition: .1s;
  119. font-weight: 500;
  120. padding: 9px 15px;
  121. border-radius: 4px;
  122. background: #409eff;
  123. border: 1px solid #409eff;
  124. color: #fff;
  125. }
  126. .parse__button:active {
  127. background: #3a8ee6;
  128. border-color: #3a8ee6;
  129. color: #fff;
  130. }
  131. h1 {
  132. font-size: 20px;
  133. margin-bottom: 20px;
  134. }
  135. pre {
  136. padding: 18px 24px;
  137. background-color: #fafafa;
  138. border: 1px solid #eaeefb;
  139. margin: 0;
  140. }
  141. </style>
  142. </html>