function getRootPath() { var strFullPath = window.document.location.href; var strPath = window.document.location.pathname; var pos = strFullPath.indexOf(strPath); var prePath = strFullPath.substring(0, pos); var postPath = strPath.substring(0, strPath.substr(1).indexOf("/") + 1); return prePath + postPath; } function RndNum(n) { var rand = ""; for (var i = 0; i < n; i++) rand += Math.floor(Math.random() * 10); return rand; } function changCode(url, width, height) { var rand = new Date().getTime(); var str = url + "data/include/imagecode.php?act=verifycode&width=" + width + "&height=" + height + "&random=" + rand + RndNum(4); $("#checkCodeImg").attr("src", str); } $(".msgbtn").click(function() { var name = $(this) .parents("form") .find("#name"); var contact = $(this) .parents("form") .find("#contact"); var content = $(this) .parents("form") .find("#content"); var checkcode = $(this) .parents("form") .find("#checkcode"); switch (true) { case name.val() == "": alert("濮撳悕涓嶈兘绌猴紒"); name.focus(); return false; break; case contact.val() == "": alert("鐢佃瘽涓嶈兘绌猴紒"); contact.focus(); return false; break; case content.val() == "": alert("瀵逛笉璧凤紝鎮ㄨ繕娌℃湁鐣欒█鍛紒"); content.focus(); return false; break; case checkcode.val() == "": alert("楠岃瘉鐮佷笉鑳戒负绌猴紒"); checkcode.focus(); return false; break; } //鐢佃瘽鍙风爜楠岃瘉 if (contact.val().length != 11) { var pattern = new RegExp(/^([0-9]{3,4})?[0-9]{7,8}$/); if (!pattern.test(contact.val())) { alert("璇疯緭鍏ユ湁鏁堢殑鐢佃瘽鍙风爜锛?); contact.focus(); return false; } } else { var pattern = new RegExp(/^1[345789]+\d{9}$/); if (!pattern.test(contact.val())) { alert("鎵嬫満鍙风爜鏍煎紡涓嶅"); contact.focus(); return false; } } var email = $(this) .parents("form") .find("#email") .val(); if (email != "") { if (!email.match( /^[a-zA-Z0-9_-]+([-_.][a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+[-.])+([a-zA-Z0-9_-]{2,3}){1,2}$/ )) { alert("閭鏍煎紡閿欒锛岃閲嶆柊杈撳叆"); email.focus(); return false; } } if (checkcode.val().length != 4) { alert("楠岃瘉鐮佹牸寮忛敊璇?); return false; } }); //杈撳叆妗嗚幏寰楃劍鐐圭殑鏃跺€欙紝鎻愮ず鍐呭娑堝け $(".m_label").click(function() { $(this).hide(); $(this) .siblings(".m_input") .focus(); }); $(".m_input").focus(function() { $(this) .siblings(".m_label") .hide(); }); $(".m_input").blur(function() { if ($(this).val() == "") { $(this) .siblings(".m_label") .show(); } }); $(".m_input").each(function() { if ($(this).val() != "") { $(this) .siblings(".m_label") .hide(); } });