goto.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. $(".banner-slider").slick({
  2. speed: 1000,
  3. swipe: true,
  4. arrows: false,
  5. });
  6. $.fn.serializeObject = function () {
  7. var o = {};
  8. var a = this.serializeArray();
  9. o["id"] = 0;
  10. o["time_stamp"] = "";
  11. $.each(a, function () {
  12. if (o[this.name]) {
  13. if (!o[this.name].push) {
  14. o[this.name] = [o[this.name]];
  15. }
  16. o[this.name].push(this.value || '');
  17. } else {
  18. o[this.name] = this.value || '';
  19. }
  20. });
  21. return o;
  22. };
  23. // email
  24. $(document).ready(function () {
  25. //E-MAIL格式檢查
  26. $("body").on("change", "#email", function () {
  27. $Emailchecking = IsEmail($("#email").val());
  28. if ($Emailchecking == false) {
  29. alert("請填寫正確的E-MAIL格式");
  30. // $("#email").blur(); //離開焦點
  31. }
  32. })
  33. function IsEmail(email) {
  34. var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  35. if (!regex.test(email)) {
  36. return false;
  37. } else {
  38. return true;
  39. }
  40. }
  41. });
  42. // phone
  43. $(document).ready(function () {
  44. //phone格式檢查
  45. $("body").on("change", "#phone", function () {
  46. $Phonechecking = IsPhone($("#phone").val());
  47. if ($Phonechecking == false) {
  48. alert("請填寫正確的手機格式");
  49. // $("#email").blur(); //離開焦點
  50. }
  51. })
  52. function IsPhone(phone) {
  53. var regex = /^[0-9]+$/;
  54. if (!regex.test(phone)) {
  55. return false;
  56. } else {
  57. return true;
  58. }
  59. }
  60. });
  61. $(".contact-form1").submit(function (e) {
  62. /* var formRef = $('#form1').serializeArray();
  63. var jsonString = JSON.stringify(formRef);*/
  64. var jsonInfo = $('.contact-form1').serializeObject();
  65. var jsonString = JSON.stringify(jsonInfo);
  66. $.ajax({
  67. type: 'POST',
  68. url: 'https://go.hhh.com.tw:8001/deco_request_detail',
  69. data: jsonString,
  70. dataType: 'json',
  71. success: function (data) {
  72. console.log('送出成功: ' + data);
  73. if (data == 0) {
  74. alert("送出成功");
  75. } else if (data == 1) {
  76. alert("此email已填過表單");
  77. } else if (data == 2) {
  78. alert("此phone已填過表單");
  79. } else if (data == 3) {
  80. alert("此email、phone已填過表單");
  81. }
  82. },
  83. beforeSend: function () {
  84. console.log('beforeSend');
  85. },
  86. complete: function () {
  87. console.log('complete');
  88. },
  89. error: function (jqXHR, textStatus, errorThrown) {
  90. console.log(JSON.stringify(jqXHR));
  91. console.log("AJAX errr: " + textStatus + ' : ' + errorThrown);
  92. console.log('送出失敗: ' + jqXHR.responseText);
  93. }
  94. });
  95. return false;
  96. });
  97. $("*").each(function (index, element) {
  98. // 此元素被點選後執行
  99. $(this).click(function (e) {
  100. // 取得被點選元素的屬性:data-gt-target
  101. var target = $(this).attr("data-gt-target");
  102. var duration = $(this).attr("data-gt-duration");
  103. var offset = $(this).attr("data-gt-offset");
  104. // JS 語法:判斷式
  105. // if (條件) {程式區塊}
  106. // 當條件成立,會執行程式區塊
  107. // 如果 目標有資料 才會執行 { } 內的程式
  108. // 避免出現 undefine (未定義 - 不存在的資料)
  109. if (target) {
  110. //console.log("目標:" + target);
  111. //console.log("時間:" + duration);
  112. //console.log("位移:" + offset);
  113. // 上方位置 = 目標區塊.位移().上方位置
  114. var top = $(target).offset().top;
  115. //console.log("要前往元素的上方位置:" + top);
  116. // 網頁元素.停止().動畫({ 上方捲動:指定元素 - 位移},持續時間)
  117. // parseInt() 將文字轉為數字
  118. $("html").stop().animate({
  119. scrollTop: top - offset
  120. }, parseInt(duration));
  121. }
  122. });
  123. });
  124. // 避免動畫與使用者滾輪衝突
  125. // html 在滾動滾輪時 停止 html 所有效果
  126. $("html").on("mousewheel", function () {
  127. $("html").stop();
  128. });
  129. $("#date").datepicker({
  130. showButtonPanel: true,
  131. });