$(function(){ var ret=0; var addTime=showTime(); promt("username","联系人不能为空!"); promt("title","标题不能为空!"); promt("content","内容不能为空!"); $("#Code").bind("focus",function(){ if(ret==0) { $("#Code").attr("class","inp ipt-focus"); $("#Code_prompt").show(); $("#Code_prompt").html("验证码不能为空!"); return false; } }); $("#Code").bind("blur",function(){ $("#Code").attr("class","inp ipt-normal"); $("#Code_prompt").hide(); return false; } ); $("#bjButton").click(function(){ $(this).focus(); var type=$(":radio[name=Type][checked]").val(); if($("#username").attr("value")=="") { $("#username").attr("class","inp ipt-focus"); $("#username_prompt").show(); $("#username").select(); $("#username_prompt").html("联系人不能为空!"); return false; } else { $("#username").attr("class","inp ipt-normal"); $("#username_prompt").hide(); } if($("#title").attr("value")=="") { $("#title").attr("class","inp ipt-focus"); $("#title_prompt").show(); $("#title").select(); $("#title_prompt").html("标题不能为空!"); return false; } else { $("#title").attr("class","inp ipt-normal"); $("#title_prompt").hide(); } if($("#content").attr("value")=="") { $("#content").attr("class","inp ipt-focus"); $("#content_prompt").show(); $("#content").select(); $("#content_prompt").html("内容不能为空!"); return false; } else { $("#content").attr("class","inp ipt-normal"); $("#content_prompt").hide(); } if($("#Code").attr("value")=="") { $("#Code").attr("class","inp ipt-focus"); $("#Code_prompt").show(); $("#Code").select(); $("#Code_prompt").html("验证码不能为空!"); return false; } else { $("#Code").attr("class","inp ipt-normal"); $.ajax({ type:"post", url:"content.asp", data:{"username":escape($("#username").attr("value")),"mobile":$("#mobile").attr("value"),"type":type,"email":$("#email").attr("value"),"title":escape($("#title").attr("value")),"content":escape($("#content").attr("value")),"addTime":escape(addTime),"Code":$("#Code").attr("value")}, success:function(json) { if(json=="0") { alert("恭喜,留言成功!\n请耐心等待管理员审核!"); $("#validate_img").attr("src","../AppCode/GetCode.asp?t="+(new Date().getTime())); $("#FeedBackForm")[0].reset(); return false; } else { $("#Code").attr("class","inp ipt-focus"); $("#Code_prompt").show(); $("#validate_img").attr("src","../AppCode/GetCode.asp?t="+(new Date().getTime())); $("#Code_prompt").html("验证码错误!"); $("#Code").select(); ret=1; return false; } }, error:function() { alert("error"); } }); } return false; }); $("#resetButton").click(function(){$("#FeedBackForm")[0].reset();}); $("#validate_img").click(function(){$("#validate_img").attr("src","../AppCode/GetCode.asp?t="+(new Date().getTime()));}); function showTime(){ var date = new Date(); //日期对象 var now = ""; now = date.getFullYear()+"-"; //读英文就行了 now = now + (date.getMonth()+1)+"-"; //取月的时候取的是当前月-1如果想取当前月+1就可以了 now = now + date.getDate()+" "; now = now + date.getHours()+":"; now = now + date.getMinutes()+":"; now = now + date.getSeconds(); //div的html是now这个字符串 return now; } function promt(prame,text) { $("#"+prame+"").bind("focus",function(){ if($("#"+prame+"").attr("value")=="") { $("#"+prame+"").attr("class","inp ipt-focus"); $("#"+prame+"_prompt").show(); $("#"+prame+"_prompt").html(text); } else { $("#"+prame+"").attr("class","inp ipt-normal"); $("#"+prame+"_prompt").hide(); } }); $("#"+prame+"").bind("blur",function(){ $("#"+prame+"").attr("class","inp ipt-normal"); $("#"+prame+"_prompt").hide(); } ); return false; } });