day66作业

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			p {
				display: none;
			}
			.red {
				background-color: #8B0000;
			}
			/* .box {
				width: 50px;
				height: 50px;
			} */
			.r {background-color: red;}
			.b {background-color: blue;}
			.g {background-color: green;}
			.active {background-color: darkred;}
		</style>
	</head>
	<body>
		<!-- 2、先有一下成绩单数据
		scores = [
			{ name: 'Bob', math: 97, chinese: 89, english: 67 },
			{ name: 'Tom', math: 67, chinese: 52, english: 98 },
			{ name: 'Jerry', math: 72, chinese: 87, english: 89 },
			{ name: 'Ben', math: 92, chinese: 87, english: 59 },
			{ name: 'Chan', math: 47, chinese: 85, english: 92 },
		]
		用table表格标签渲染以上数据,表格第一列是学生总分排名,最后一列是学生总分;
		
		3、还是采用上方相同的数据,采用相同的渲染规则,只渲染所有科目都及格了的学生。 -->
		<!-- 1、还是采用上方相同的数据,添加筛选规则:
			i)有三个按钮:语文、数学、外语,点击谁谁高亮,且当前筛选规则采用哪门学科
			ii)两个输入框,【】~【】,前面天最小分数,后面填最大分数,全部设置完毕后,表格的数据会被更新只渲染满足所有条件的结果
			举例:点击语文,输入【86】~【87】,那就只会渲染Jerry和Ben两条数据 -->
			
			
			<div id="app">
				
				<p v-for="v in scores">
					<!-- {{v.name}}的分数:
					math:{{ v.math }}
					chinese:{{v.chinese}}
					english:{{v.english}} -->
					{{v.math, v.chinese, v.english|fn(v.name)}}
				</p>
				
				<!-- <p v-for="i in result">
					{{i.name}}:{{i.grade}}
				</p> -->
				<div>成绩表:高亮的学生名字表示各科成绩及格<div>
				<hr>
				<table border="3" cellpadding="10">
					<thead>
						<tr>
							<th>排名</th>
							<th>学生名称</th>
							<th>数学成绩</th>
							<th>语文成绩</th>
							<th>英语成绩</th>
							<th>总分数</th>
						</tr>
					</thead>
					<tbody v-for="v,i in result">
						<tr>
							<td>{{i+1}}</td>
							<td class="red" v-if="is_pass === v.math > 60 & v.chinese >60 & v.english > 60">{{v.name}}</td>
							<td v-else="is_pass">{{v.name}}</td>
							<td>{{v.math}}</td>
							<td>{{v.chinese}}</td>
							<td>{{v.english}}</td>
							<td>{{v.grade}}</td>
						</tr>
					</tbody>
				</table>
				
				<hr>
				
				
				<!-- 第二题有bug -->
				<div>
				    <div>
						<input type="button" @click="page='r_page'" :class="{active:page === 'r_page'}" value="语文"  v-if="page === 'r_page'">
						<input type="button" @click="page='b_page'" :class="{active:page === 'b_page'}" value="数学">
						<input type="button" @click="page='g_page'" :class="{active:page === 'g_page'}" value="英语">
				        <!-- <button type="button" @click="page='r_page'" :class="{active:page === 'r_page'}">语文</button>&nbsp;&nbsp;
				        <input type="button" @click="page='b_page'" :class="{active:page === 'b_page'}">数学</button>&nbsp;&nbsp;
				        <button type="button" @click="page='g_page'" :class="{active:page === 'g_page'}">英语</button>&nbsp;&nbsp; -->
						<div v-if="page === 'r_page'" class="box r"></div>
						    <div v-else-if="page === 'b_page'" class="box b" ></div>
						    <div v-else class="box g"></div>
				    </div>
				</div>
			</div>
	
	</body>

	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	<script type="text/javascript">
		var total_grade = [];
		let app = new Vue({
			el:'#app',
			data:{
				total:0,
				is_pass:true,
				page:'r_page',
				scores:[
					{ name: 'Bob', math: 97, chinese: 89, english: 67 },
					{ name: 'Tom', math: 67, chinese: 52, english: 98 },
					{ name: 'Jerry', math: 72, chinese: 87, english: 89 },
					{ name: 'Ben', math: 92, chinese: 87, english: 59 },
					{ name: 'Chan', math: 47, chinese: 85, english: 92 },
				]
			},
			filters:{
				fn(math,chinese,english,name){
					// console.log(a,b,c)
					let total = math + chinese + english
					// console.log(total_grade,total,name)
					this.total = total
					console.log(name,total_grade)
					total_grade.push({'name':name,'math':math,'chinese':chinese,'english':english,'grade':total})
					
					return total
				}
			},
			computed:{
				result(){
					for (let i=0;i<total_grade.length-1;i++){
					        for (j=0;j<total_grade.length-1-i;j++){
					            if (total_grade[j].grade > total_grade[j+1].grade){
					                let tmp = total_grade[j]
					                total_grade[j] = total_grade[j+1]
					                total_grade[j+1] = tmp
					            }
					            
					        }
					    };
						return total_grade
				}
					
			},
		})
	</script>
</html>
posted @ 2019-12-17 22:45  GeminiMp  阅读(87)  评论(0)    收藏  举报