Blogger Information
Blog 15
fans 0
comment 0
visits 10354
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
ToList留言并添加删除功能2019.1.17
ken的博客
Original
602 people have browsed it

 

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h1>请留言</h1>
	<input type="" name="">
	<ul></ul>
    <script type="text/javascript">
    	var input = document.getElementsByTagName('input')[0];
    	var ul = document.getElementsByTagName('ul')[0];
    	input.focus();
    	input.onkeydown = function (event) {
    		if(event.keyCode===13){

    		var li = document.createElement('li');

    		li.innerHTML =  input.value + '<a href="javascript:;" onclick="del(this)">删除</a>';
    		if(ul.ChildElementCount ===0){
    		ul.appendChild(li);	
    		}else{
    		    // 获取当前第一个子元素
    			var first = ul.firstElementChild;
    			//已有留言,则插入到新一条之前
    			ul.insertBefore(li,first);
    		}

    		input.value = '';//清空内容

    		}

    	}
           function del(ele){
        	if(confirm('是否删除')){
        		ul.removeCild
        	}
        	else{
        		return false;
        	}

        }


    </script>

</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post