首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

Ajax无刷新修改数据,当输入的时间格式不对时如何提示?有代码

2013-06-19 
Ajax无刷新修改数据,当输入的时间格式不对时怎么提示?有代码index.asphtml xmlnshttp://www.w3.org/199

Ajax无刷新修改数据,当输入的时间格式不对时怎么提示?有代码
index.asp


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<!--#include file="adoconn.asp"-->
<!--#include file="identify.asp"-->

<table width="600" border="0" cellspacing="0" cellpadding="0" align="center">  
  <tr>
    <td colspan="2" id="xueshengku_html" style="padding-left:0px;"></td>
  </tr>
</table>
<body>
<form action="" method="post" name="form1">
<div id="add_plan">
<table width="403"   cellspacing="1" cellpadding="1" border="0">

  <tr>
    <td align="left" bgcolor="#009999"><font size="2" color="#000000">时间:</font>
  <input name="ph" type="text" id="ph" size="7" value="0">
      <input name="fsj" type="text" id="fsj" size="7" value="<%=formatdatetime(now,3)%>">
    <td align="center"><input name="add_plan2" type="button" id="add_plan2" value="添加" onClick="javascript:add1();window.location.reload();"/> <input name="reset" type="reset" id="reset" value="关闭" onClick="javascript:close1();"/></td>
  </tr>
  </table>
  

</form>
</div>
</body>

<div id="edit_plan" style="background-color:#ffffff; height:130px;" ></div>
<script language="javascript" src="jquery.js"></script>
<script language="javascript" src="modify_ajax_yc.js"></script>


<script language="javascript">
$.post("plan2.asp?jihao1=<%=request("jihao1")%>&jihao2=<%=request("jihao2")%>&xingm=<%=request("xingm")%>",{act:"list"},
function(data)
{  
$("#xueshengku_html").html(data);
}
); 
function fpage(str)
{
    //这里要分割str
m=str.replace("?","");
n=m.split("&");
ko='';
page=1;
for(i=0;i<n.length;i++)
{
  s0=n[i];//得到 page=2 act=list id=578
  s1=s0.split("="); 
  if(s1[0]=="page")
  {
     page=s1[1];
  }   
}
    $.post("plan2.asp?jihao1=<%=request("jihao1")%>&jihao2=<%=request("jihao2")%>&xingm=<%=request("xingm")%>",{act:"list",page:page},
function(data)
{  
$("#xueshengku_html").html(data);
}
    ); 
}
function edit1(id)
{   
    $.post("plan2.asp?jihao1=<%=request("jihao1")%>&jihao2=<%=request("jihao2")%>&xingm=<%=request("xingm")%>",{id:id,act:"edit"},
function(data)

    str=data.split("|");
//alert(str);
str0='<table width="100%" border="1" cellspacing="0" cellpadding="0"></table>'; 
document.getElementById("edit_plan").innerHTML=str0;
//$("#edit_plan").html(str0);
$("#edit_plan").css("display","block"); 
}
    );   
}
function del1(id,page)

{
    $.post("plan2.asp?jihao1=<%=request("jihao1")%>&jihao2=<%=request("jihao2")%>&xingm=<%=request("xingm")%>",{id:id,act:"del",page:page},


function(data)

    $("#xueshengku_html").html(data);
}
    );   
}

function open1()
{
   $("#add_plan").css("display","block");
}
function close1()
{
    $("#add_plan").css("display","none");
}
function close2()
{
    $("#edit_plan").css("display","none");
}
function add1()
{   
ph=$("#ph").val();
fsj=$("#fsj").val();

   $.post("plan2.asp?jihao1=<%=request("jihao1")%>&jihao2=<%=request("jihao2")%>&xingm=<%=request("xingm")%>",{
ph:escape(ph),
fsj:fsj,
   act:"add"
   },
  function(data){   
      // alert(data);
$("#ph").val('');
$("#fsj").val('');
  close1();
          $("#xueshengku_html").html(data);         
      }
   ); 
}
</script>
</body>
</html>


plan2.asp

<!-- #include file="adoconn.asp" -->

<%
'=========================================
'功能:ajax实现无刷新对数据库的操作
'有添加、删除、修改、分页
'使用的是jquery框架
'作者:wangsdong
'=========================================

'此为后台文件
Response.CacheControl = "no-cache"
response.addheader"content-type","text/html;charset=gb2312"
id=request("id")
set rs=server.CreateObject("adodb.recordset")
   act=request("act")   
   if act="" or act="add" then
     call add()
   elseif act="list" then
      call manage()
   elseif act="del" then
      call del()
   elseif act="modify" then
      call modify()
   ElseIf act="edit" Then
      Call edit()
   end If
sub del() '删除

   page=request("page")
   sql="delete from xueshengku where object_id="&id
   conn.execute(sql)   
   Call manage()   
end sub
   
sub add() '添加
ph = VbsUnEscape(request("ph"))
fsj = request("fsj")

sql="select * from xueshengku where object_id=null"
rs.open sql,conn,1,3
rs.addnew
rs("ph")=ph
if fsj<>"" then rs("fsj")=fsj


rs.update
rs.close 
Call manage()
end sub   
sub manage()  '分页   
%>
<%
jihao1 = request("jihao1")
jihao2 = request("jihao2")
xingm = request("xingm")
sql="select ph,fsj from xueshengku where cdate(rq+' '+fsj)>=#"&jihao1&" "&jihao2&"# or xingm like'%"+xingm+"%'order by object_id desc"
rs.open sql,conn,1,1
k=1
If rs.eof Then
Else
    rs.pagesize=4
    page=request("page")
    If Not Isnumeric(page) or page="" Then


      page=1
    else
      page=cint(page)
    End if
    if page<1 then page=1
    if page>rs.pagecount then page=rs.pagecount
    rs.AbsolutePage = page

    for i=1 to rs.pagesize
    ph = rs("ph")
    rq = trim(rs("rq"))
fsj= trim(rs("fsj"))
 if isnull("fsj") then fsj="&nbsp;"


    '******************下面是你要显示的******************'
if i mod 2= 0 then
  bgcolor="#eeeeee"
else
  bgcolor="#ffffff"
end if
response.write ("<table width='900' border='0'><tr><td bgcolor='#999999'><p align='center'><span id=""gname9"&object_id&""" name=""gname9"&object_id&"""><input type=""text""  size=""5"" value="&fsj&" maxlength=""20""  style=""border:1px solid #FFFFFF; text-align:center; ime-mode:Disabled; color:#800000; font-weight:bold;text-align:center; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px; background-color:#FFFFFF; cursor:hand;"" onClick=""forder2('"&object_id&"','"&fsj&"','xueshengku','fsj','object_id','gname9');""></span></p></td><td bgcolor='#ffffff'><p align='center'><span id=""gname10"&object_id&""" name=""gname10"&object_id&"""></td></tr></table>")
    '******************上面是你要显示的******************'
    rs.movenext
k=k+1
    if rs.eof then
      Exit For
    End if
    next
response.write "<tr><td height=""22"" colspan=6>"
call fpage("act",page)
response.write "</td></tr>"
response.write "</table>"
end if
'call fpage("id")
rs.close
set rs=nothing
end sub
set conn=nothing

Function fpage(str,page) '分布函数
s=Split(str,"|")
s2=""
For i=0 To UBound(s)
  s2=s2&"&"&s(i)&"="&request(s(i))
next
response.write "<table width=""100%"" cellpadding=0 cellspacing=0 border=0>"
response.write " <tr>"
response.write " <td align=""center"" width=""95%"">&nbsp;&nbsp;信息总数:"&rs.recordcount&"个 页次:"&page&"/"&rs.pagecount&"页"
If page<=1 Then
  response.write " 首&nbsp;页 上一页 "
Else
  response.write " <a href=""javascript:;"" onclick=""javascript:fpage('?page=1"&s2&"')""><font color='#ff0000'>首&nbsp;页</font></a> <a href=""javascript:;"" onclick=""javascript:fpage('?page="&(page-1)&s2&"')""><font color='#ff0000'>上一页</font></a> "
End If
If page>=rs.pagecount Then
  response.write "下一页 尾&nbsp;页 "
Else
  response.write "<a href=""javascript:;"" onclick=""javascript:fpage('?page="&(page+1)&s2&"')""><font color='#ff0000'>下一页</font></a> <a href=""javascript:;"" onclick=""javascript:fpage('?page="&rs.pagecount&s2&"')""><font color='#ff0000'>尾&nbsp;页</font></a>"


End If
response.write "</td> "
response.write " <td width=""5%""></td>"
response.write " </tr>"
response.write "</table>"
End function

'与javascript中的escape()等效
    Function VbsEscape(str)
        dim i,s,c,a 
        s="" 
        For i=1 to Len(str) 
            c=Mid(str,i,1)
            a=ASCW(c)
            If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
                s = s & c
            ElseIf InStr("@*_+-./",c)>0 Then
                s = s & c
            ElseIf a>0 and a<16 Then
                s = s & "%0" & Hex(a)
            ElseIf a>=16 and a<256 Then
                s = s & "%" & Hex(a)
            Else
                s = s & "%u" & Hex(a)
            End If
        Next
        VbsEscape=s
    End Function
    '与javascript中的unescape()等效
    Function VbsUnEscape(str)
                    Dim x
        x=InStr(str,"%") 
        Do While x>0
            VbsUnEscape=VbsUnEscape&Mid(str,1,x-1)
            If LCase(Mid(str,x+1,1))="u" Then
                VbsUnEscape=VbsUnEscape&ChrW(CLng("&H"&Mid(str,x+2,4)))
                str=Mid(str,x+6)
            Else
                VbsUnEscape=VbsUnEscape&Chr(CLng("&H"&Mid(str,x+1,2)))
                str=Mid(str,x+3)
            End If
            x=InStr(str,"%")
        Loop
        VbsUnEscape=VbsUnEscape&str


    End Function
%>


Ajax
[解决办法]
index.asp,plan2.asp服务器端都增加时间验证

index.asp
<%
if not isdate(request("jihao1")&" "&request("jihao2")) then
  response.Write "时间格式不对!"
  response.End
end if
 %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<!--#include file="adoconn.asp"-->
<!--#include file="identify.asp"-->

plan2.asp
<!-- #include file="adoconn.asp" -->
 <%
if not isdate(request("jihao1")&" "&request("jihao2")) then
  response.Write "时间格式不对!"
  response.End
end if
 %>



    function check(v) {
        if (v.match(/^(((0
[解决办法]
1)\d)
[解决办法]
(2[0-3])):[0-5][0-9]$/)) {
            return true
        }
        else {
            alert('请以hh:mm格式输入时间');
            return false
        }
    }
    /*
    id为要修改的记录ID
    v是当前默认值
    tablename表名
    fname为字段名
    gname为id的字段名
    */
    function forder2(id, v, tablename, fname, gname, str5) {
        str = '<input type="text" size="5" value="' + id + '">';

        str2 = '<input id="kk' + id + '"style="text-align:center" type="text" size="5" value="' + v + '" onblur="fchangeorder2(' + id + ',this.value,\'' + v + '\',\'' + tablename + '\',\'' + fname + '\',\'' + gname + '\',\'' + str5 + '\');">';
        //alert(str2);
        $("#" + str5 + id).html(str2);
        $("#kk" + id).focus();
        $("#kk" + id).select();
    }
    function fchangeorder2(id, v, v1, t1, fname, gname, str5) {
        if (!check(v)) return false;
        $.post("modify_ajax.asp", { id: id, v: v, t1: t1, fname: fname, gname: gname },
         function (data) {


             if (data == 1) {
                 str = '<input type="text" size="5" value="' + v + '" maxlength="20"  style="border:1px solid #FFFFFF; ime-mode:Disabled; color:#800000; font-weight:bold; background-color:#FFFFFF; cursor:hand; text-align:center;" onClick="forder2(\'' + id + '\',\'' + v + '\',\'' + t1 + '\',\'' + fname + '\',\'' + gname + '\',\'' + str5 + '\');">'
                 $("#" + str5 + id).html(str);
             }
             else {
                 $("#" + str5 + id).html(v1);
             }
         }
     );
    }

热点排行