<form name="form1"> <input name="dsfurl" type="hidden" id="dsfurl"> <table border="0" class="yy"> <tbody> <tr> <td align="center"><input name="name" id="name" type="text" class="shur" value="" placeholder="请输入您的姓名" ></td> </tr> <tr> <td align="center"><input id="haoma" name="tel" type="text" class="shur" value="" placeholder="请输入联系电话" ></td> </tr> <tr> <td align="center" class="field1" style="height:30px"> <select type="text" name="yy" id="dateinfo" class="shur" style="width: 280px;background: #fff;"> <option value=‘‘>请选择您的预约日期</option> <script language="javascript"> //构造当前日期对象 var myDate = new Date(); //获取年份 var year = myDate.getFullYear(); //获取当前月份 var mouth = myDate.getMonth() + 1; //定义当月的天数; var days; //当月份为二月时,根据闰年还是非闰年判断天数 if (mouth == 2) { days = year % 4 == 0 ? 29 : 28; }else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 ||mouth == 12) { //月份为:1,3,5,7,8,10,12 时,为大月.则天数为31; days = 31; }else { //其他月份,天数为:30. days = 30; } var syu=days-myDate.getDate(); if(syu < 7){ for(var i = 0; i <=7; i++) { time = (myDate.getMonth() + 1) + "月" + myDate.getDate() + "日"; document.write("<option value=‘" + time + "‘>" + time + "</option>"); myDate.setDate(myDate.getDate() + 1); } }else{ for(var i = 0; i <= syu; i++) { time = (myDate.getMonth() + 1) + "月" + myDate.getDate() + "日"; document.write("<option value=‘" + time + "‘>" + time + "</option>"); myDate.setDate(myDate.getDate() + 1); } } </script> </select> </td> </tr> <tr> <td align="center"><textarea name="bq" id="bq" cols="" rows="" class="shur2" placeholder="请简要描述一下" ></textarea></td> </tr> <tr> <td align="center" ><input type="button" class="anniu" id="submit" value="点击提交预约信息" onclick="return checkgh(document.form1)";></td> </tr> <tr> <td align="center"> <p class="g-foot">温馨提示:工作人员将在一个工作日内与您联系!</p></td> </tr> </tbody> </table> </form> <script language="javascript"> document.getElementById(‘dsfurl‘).value=document.referrer; </script>
js代码:
function checkgh(fm) { if (fm.name.value == ‘‘) { alert(‘请输入您的名字‘); window.setTimeout(function () { fm.name.focus(); }, 0); return false; } if (fm.tel.value == ‘‘) { alert(‘请输入您的联系方式‘); window.setTimeout(function () { fm.tel.focus(); }, 0); return false; } if (!isMobile(fm.tel.value)) { alert("请填入正确的联系号码"); window.setTimeout(function () { fm.tel.focus(); }, 0); return false; } submitForm(fm); return true; } var trueStr = ‘您已成功预约!‘; var falseStr = "很抱歉,预约失败!"; function submitForm(form) { if (getCookie("submitcache") != null) { if (new Date().getTime() - getCookie("submitcache") < 1000 * 30) { alert("30秒内不能重复提交,请稍后再尝试提交!"); return false; } } var xmlHttp = createXmlHttp(); if (!xmlHttp) { alert(falseStr); return 0; } var url = ‘https//www.5z.com/gh22.php‘; var postData = ""; var subtnchar = form.submit.value; for (var i = 0; i < form.length; i++) { postData += form.elements[i].name + "=" + form.elements[i].value + "&"; } xmlHttp.open("POST", url, true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;&charset=utf-8"); xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { if (xmlHttp.responseText.indexOf("ok") != -1) { try { document.cookie = "submitcache=" + new Date().getTime(); } catch (e) {} alert(trueStr); form.reset(); } else if (xmlHttp.responseText.indexOf("err") != -1) { alert(falseStr); form.reset(); } else { var jsonString = xmlHttp.responseText; alert(jsonString.substring(11, jsonString.length - 2)); } form.submit.value = subtnchar; form.submit.disabled = false; } } form.submit.value = "数据提交中……"; form.submit.disabled = true; xmlHttp.send(encodeURI(postData)); return true; } function createXmlHttp() { var xmlHttp = null; try { xmlHttp = new XMLHttpRequest(); } catch (e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function isMobile(s) { if (!(/^((1[34578]\d{9})|(0\d{10,11}))$/.test(s))) { return false; } return true; } function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; }
php文件执行的结果
1,执行成功 返回status:ok;
2,执行不成功,返回status:err;
时间: 2024-10-12 12:46:50