Blogger Information
Blog 34
fans 0
comment 1
visits 23395
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
DOM操作与实战案例 —2018年9月14日23时45分
感恩的心的博客
Original
666 people have browsed it

1、编程:实例演示 id,class,标签和css选择器获取元素的方法

实例

<style type="text/css">
        .classExample {
                width: 90%;
                height:80px;
                margin: auto;
        }



</style>

<script>
let btn=document.getElementsByTagName('button')[0];
let text=document.getElementsByName('text')[0];
let text=document.getElementsByClassName('red')[0];
let list=document.getElementById('id1');

<script>

运行实例 »

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



2、实战: 在线聊天机器人

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>DOM实战:模拟智能在线***系统</title>
        <style type="text/css">
        div:nth-child(1) {
                width: 450px;
                height: 650px;
                background-color: lightskyblue;
                margin: 30px auto;
                color: #333;
                box-shadow: 2px 2px 2px #808080
        }
		
        h2 {
                text-align: center;
                margin-bottom: -10px;
        }
        div:nth-child(2) {
                width: 400px;
                height: 500px;
                border: 4px double green;
                background-color: #efefef;
                margin: 20px auto 10px;
        }
		
        ul {
                list-style: none;
                line-height: 2em;
                /*border: 1px solid red;*/
                overflow: hidden;
                padding: 15px;
        }

        table {
                width: 90%;
                height:80px;
                margin: auto;
        }

        textarea{
                /*width: 300px;*/
                border: none;
                resize: none;
                background-color: lightyellow;
			
        }
        button {
                width: 60px;
                height: 40px;
                background-color: seagreen;
                color: white;
                border: none;
                /*text-align: left;*/

        }
        button:hover {
                cursor: pointer;
                background-color: orange;
        }
        </style>
</head>
<body>

	<div>
		<h2>在线***</h2>
		<div contenteditable="true">
			<ul>
				<li></li>
			</ul>
		</div>
		<table>
		<tr>
			<td align="right">
				<textarea name="text" cols="50" rows="4"></textarea>
			</td>
			<td align="left"><button type="button">发送</button></td>
		</tr>
	</table>
	</div>

	<script>
		let btn=document.getElementsByTagName('button')[0];
		let text=document.getElementsByName('text')[0];
		let list=document.getElementsByTagName('li')[0];
		let sum=0;

		btn.onclick=function(){
			if(0===text.value.length){
                            alert("内容为空,请重新输入!");
                            return false;
                        }
                        let userInput=text.value;
                        
                        let userLi=document.createElement('li');
                        let userPic='<img src="pic/user.jpg" width="30" style="border-radius:50%">'; 
                        userLi.innerHTML=userPic+userInput;
                        list.appendChild(userLi);
                        text.value='';
                        setTimeout(function(){
                            let replyMsg=[
                                '戒为良***!不泄为补!',                         
                                '她们只是诱饵,症状才是里面的钩子,症状是不会放过你的。',
                                '他们喜欢,我害怕,因为我深知危害之惨烈!',
                                '出症状了,就知道怕了!',
                                '你让自己爽,症状让你苦!',
                                '从天堂到地狱,你撸过人间。',
                                '戒到死,戒到地球爆炸!',
                                '不戒,你就完了,戒了,就是重生!',
                                '沉迷手淫,必招症状缠身,这是几千个案例揭示的真理!',
                                '把戒色当作人生最佳的历练,Just 戒 it!',
                                '你掏空自己的***精,医院掏空你的***!所谓人财两空!'                                
                            ];
                            let randomNum=Math.floor(Math.random()*replyMsg.length);
                            let replyPic='<img src="pic/reply.jpg" width="30" style="border-radius:50%">'; 
                            let replyLi=document.createElement('li');
                            replyLi.innerHTML=replyPic+replyMsg[randomNum];
                            list.appendChild(replyLi);
                      
                            
                        },2000);
		};







	</script>


	
</body>
</html>

运行实例 »

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

 

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