打卡

来源:1-19 自由编程

home_11

2021-05-18 10:06:02

<!DOCTYPE html >

<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery练习</title>

<style type="text/css">
.div1{

	float: left;
	width: 50px;
	line-height: 30px;
	background-color: lightgray;
	margin-left: 10px;
	text-align: center;
	vertical-align: middle;
}
.div2{
	width: 300px;
	height: 300px;
	border: solid gray 1px;
	margin-top: 60px;
	color: red;
}
</style>


</head>
<body>
	<h2>请选择背景颜色</h2>
	<div>
	<div id="blue" class="div1">蓝色</div>
	<div id="green" class="div1">绿色</div>
	</div>
	<div class="div2" id="bg">
	</div>
	<div>输入颜色首字母: <input type="text" name="color"></div>
	<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
	<script type="text/javascript">
	
		// 加载页面时执行
		window.onload = function(){
			alert("欢迎来到设置颜色的界面");
		}
		
		$("div[id='green']").on("click", function() {
			$("div.div2").html("<p>绿色背景</p>");
			$("div.div2").css({"background-color" : "green" , "color" : "red", "font-weight" : "bold" , "font-style" : "italic"});
		});
		
		$("div[id='blue']").on("click", function blue() {
			$("div.div2").html("<p>蓝色背景</p>");
			$("div.div2").css({"background-color" : "blue" , "color" : "red"});
		});
		
		$("input[name='color']").keypress(function(event) {
			$("div.div2").html("");
			if(event.keyCode == 71) {
				$("div.div2").css("background-color" ,"green");
			} else if(event.keyCode == 66) {
				$("div.div2").css("background-color" ,"blue");	
			}
		});

		
	</script>
</body>
</html>
写回答

1回答

好帮手慕小尤

2021-05-18

同学你好,已完成练习,棒棒哒!继续加油!

祝学习愉快!

0

0 学习 · 16556 问题

查看课程

相似问题

打卡

回答 1

打卡

回答 1

打卡

回答 1

打卡

回答 1

练习打卡

回答 1