【发布时间】:2018-02-20 01:13:25
【问题描述】:
解决这个任务。给出了CSS和html代码!但是添加 div 标签功能不起作用。 html页面移除后如何添加div标签?
编写以下代码:
a) 编写 CSS 类标题块:边框 1,颜色-蓝色,字体大小-20,字体名称-arial,内边距 50px。
b) 编写 CSS 类页脚块:边框 1,颜色-黑色,高度-20%,宽度-100%,背景颜色-灰色;
c) 为单击按钮时添加页眉块类和页脚块编写一个 jquery 代码。
d)为单击按钮时删除页眉块类和页脚块编写一个 jquery 代码。
e) 为单击按钮时的 Toggle Header 块 Class 和 Footer 块编写 jquery 代码。
$(document).ready(function() {
$('.remove').click(function() {
$('.header').remove();
$('.footer').remove();
});
});
$(document).ready(function() {
$('.add').click(function() {
$('body').addClass('div.header');
$('body').addClass('div.footer');
});
});
.header {
border: 1px solid;
color: blue;
font-size: 20;
font-family: arial;
padding: 50px;
}
.footer {
border: 1px solid;
color: black;
height: 20%;
width: 100%;
background-color: grey;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<link rel='stylesheet' style='text/css' href='a30.css'></link>
<script src='../jquery.js'></script>
</head>
<body>
<div class='header'>
This is header!
</div>
<button class='add'>Add</button>
<button class='remove'>Remove</button>
<div class='footer'>
This is footer!
</div>
</body>
</html>
请帮我找到解决办法!
【问题讨论】:
-
一旦从 DOM 中删除,您需要完全重新创建丢失的 html。你可以将它保存在一个变量中,或者只在 Jquery 中使用 .show() 和 .hide()
标签: javascript jquery html css