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) { var rand = new date().gettime(); var str = url + 'data/include/imagecode.php?act=verifycode&random=' + rand + rndnum(4); $("#checkcodeimg").attr("src", str); } function changcode1(url) { var rand = new date().gettime(); var str = url + 'data/include/imagecode.php?act=verifycode&random=' + rand + rndnum(4); $("#checkcodeimg1").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[34578]+\d{9}$/); if (!pattern.test(contact.val())) { alert('手机号码格式不对'); contact.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(); } });