模拟留言板

<!--
智能社© - http://www.zhinengshe.com/

微博:@北京智能社
微信:zhi_neng_she

最具深度的前端开发培训机构 HTML+CSS/JS/HTML5
-->


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>模拟留言板 - 智能社 - www.zhinengshe.com</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: 100px; height: 30px; border: 1px solid #ccc; background: #fff; color: #666; font-size: 14px; position: relative; left: 42px; }
#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>
window.onload=function (){
    var oInp=document.getElementById('text');
    var oTextarea=document.getElementsByTagName('textarea')[0];    
    var oBtn=document.getElementById('btn');
    var oDiv=document.getElementById('message_text');
    var oUl=oDiv.getElementsByTagName('ul')[0];
    
    oBtn.onclick=function (){
        var sTit=oInp.value;
        var sText=oTextarea.value;
        var oLi=document.createElement('li');
        oLi.innerHTML='<h3>'+sTit+'</h3><p>'+sText+'</p>';//innerHTML离3插入标签式亮点
        if( oInp.value == "" || oTextarea.value == "" )
        {
            alert("二个框,你还不写全了啊?");
            return;
        }
        if(oUl.children.length==0)
        {
            oUl.appendChild(oLi);
            oDiv.style.display='block';
        }
        else
        {
            oUl.insertBefore(oLi,oUl.children[0]);
            oDiv.style.display='block';
        }
                  /*这种方式让我大脑洞开,狂欢呀*/
        /*if(oUl.children[0])
        {
            oUl.insertBefore(oLi,oUl.children[0]);
            oDiv.style.display='block';
        }
        else
        {
            oUl.appendChild(oLi);
            oDiv.style.display='block';
        }*/
        oInp.value='';
        oTextarea.value='';
        oInp.focus();
        
    };
};
</script>
</head>

<body>
<div id="box">
    <ul id="fill_in">
        <form>
            <li>姓名:<input id="text" type="text" class="text" /></li>
            <li>内容:<textarea></textarea></li>
            <li><input id="btn" type="button" value="提交" class="btn" /></li>
        </form>
    </ul>
    <div id="message_text">
        <h2>显示留言</h2>
        <ul>
            <!--
            <li>
                <h3>标题</h3>
                <p>文字</p>
            </li>
            -->
        </ul>
    </div>
</div>
</body>
</html>
    

 

转载于:https://www.cnblogs.com/heboliufengjie/p/4163835.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值