zoukankan      html  css  js  c++  java
  • Ajax无刷新提交表单和显示

    ajax无刷新表单提交:

     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>Ajax留言本</title> 
    <style type="text/css"> 
    * { padding: 0; margin: 0; } 
    li { list-style: none; } 
    body { background: #f9f9f9; font-size: 14px; } 
    #box { width: 450px; padding: 10px; border: 1px solid #ccc; background: #f4f4f4; margin: 10px auto; } 
    #fill_in { margin-bottom: 10px; } 
    #fill_in li { padding: 5px 0; } 
    #fill_in .text { width: 380px; height: 30px; padding: 0 10px; border: 1px solid #ccc; line-height: 30px; font-size: 14px; 
    font-family: arial; } 
    #fill_in textarea { width: 380px; height: 100px; line-height: 20px; padding: 5px 10px; border: 1px solid #ccc; font-size: 
    14px; font-family: arial; overflow: auto; vertical-align: top; } 
    #fill_in .btn { border: none; width: 120px; height: 30px; border: 1px solid #ccc; background: #fff; color: #666; font-size: 
    14px; position: relative; left: 42px; } 
    #fill_in .ret { border: none; width: 120px; height: 30px; border: 1px solid #ccc; background: #fff; color: #666; font-size: 
    14px; position: relative; left: 42px;margin-left:50px; } 
    #message_text { display: none; } 
    #message_text h2 { font-size: 14px; padding: 6px 0 4px 10px; background: #ddd; border-bottom: 1px solid #ccc; } 
    #message_text li { background: #f9f9f9; border-bottom: 1px solid #ccc; color: #666; overflow: hidden; } 
    #message_text h3 { padding: 10px; font-size: 14px; line-height: 24px; } 
    #message_text p { padding: 0 10px 10px; text-indent: 28px; line-height: 20px; } 
    </style> 
    <script type="text/javascript"> 
    var oBtn = null; 
    var oForm = null; 
    var oText = null; 
    var oTextarea = null; 
    var timer = null; 
    var speed = 0; 
    var oLi = null 
    var oH3 = null; 
    var oP = null; 
    window.onload = function() 
    { 
    oBtn = document.getElementById("btn"); 
    oBtn.onclick = getValue; 
    }; 
    function getValue() 
    { 
    document.getElementById("message_text").style.display = "block"; 
    oForm = document.getElementsByTagName("form")[0]; 
    oText = document.getElementById("text"); 
    oTextarea = document.getElementsByTagName("textarea")[0]; 
    oUl = document.getElementById("message_text").getElementsByTagName("ul")[0]; 
    oForm.onsubmit = function(){ return false; }; 
    if( oText.value == "" || oTextarea.value == "" ) 
    { 
    alert("就二个框,你还不写全了啊?"); 
    return; 
    } 
    oLi = document.createElement("li"); 
    oH3 = document.createElement("h3"); 
    oP = document.createElement("p"); 
    oH3.innerHTML = oText.value; 
    oP.innerHTML = oTextarea.value; 
    if(oUl.childNodes[0]) 
    { 
    oUl.insertBefore(oLi,oUl.childNodes[0]); 
    } 
    else 
    { 
    oUl.appendChild(oLi); 
    } 
    oLi.appendChild(oH3); 
    oLi.appendChild(oP); 
    oText.value = ""; 
    oTextarea.value = ""; 
    var h = oLi.offsetHeight; 
    oLi.style.height = '0px'; 
    if(timer) 
    { 
    clearInterval(timer); 
    } 
    timer = setInterval("goTime("+h+")", 35); 
    goTime(h); 
    } 
    function goTime(target) 
    { 
    var top = oLi.offsetHeight; 
    speed += 3; 
    top += speed; 
    if(top > target) 
    { 
    top = target; 
    speed *= -0.7; 
    } 
    if(top===target && Math.abs(speed) < 3) 
    { 
    clearInterval(timer); 
    timer = null; 
    oLi.style.height = target + "px"; 
    } 
    oLi.style.height = top + "px"; 
    } 
    </script> 
    </head> 
    <body> 
    <div id="box"> 
            <h3>请留下您的足迹:</h3> 
        <div id="message_text"> 
            <h2>显示留言:</h2> 
            <ul></ul> 
        </div> 
        
        
        <ul id="fill_in"> 
            <form> 
                <li>姓名:<input id="text" type="text" class="text" /></li> 
                <li>内容:<textarea id="content" style="300px; height:100px"></textarea></li> 
                <li><input id="btn" type="submit" value="提交" class="btn" /><input id="ret" type="reset" value="重写" class="ret" /></li> 
            </form> 
        </ul> 
        
    
    </div> 
    </body> 
    </html>

     实例截图:

  • 相关阅读:
    Kubernetes 升级过程记录:从 1.17.0 升级至最新版 1.20.2
    歼10:职业有个基本属性,为了糊口。然后再区分 主动 or 被动,被动者只是为了糊口,那自然是看不起自己的职业
    红胖子:写给人生的九封信,愿你的人生淡定从容,繁华似锦!!!
    Embarcadero MVP(68位,全部都有个人主页)
    Delphi 26 岁
    C# Assembly 与 Reflection
    你精通那么多技术,为何还是做不好一个项目
    Linux 6 个“吓人”的 命令
    Distributed Application runtime
    RocketMQ and kafka
  • 原文地址:https://www.cnblogs.com/sunxun/p/5213785.html
Copyright © 2011-2022 走看看