$(document).on('click','.item',function(){
let data = $(this).siblings();
for(let i = 0;i<data.length; i++){
$(data[i]).children().eq(-1).addClass("disnone")
if($(this).children().eq(-1).hasClass("disnone")){
$(this).addClass("main_hover").siblings().removeClass("main_hover");
$(this).children().eq(-1).removeClass("disnone");
}else{
$(this).removeClass("main_hover").siblings().removeClass("main_hover");
$(this).children().eq(-1).addClass("disnone");
html文件:(全码)
<!DOCTYPE html>
<meta charset="utf-8">
<title>历史上的今天</title>
<script src="./jquery-2.1.4.min.js"></script>
</head>
<style>
padding: 0;
margin: 0;
.container{
width: 1200px;
min-height: 800px;
box-sizing: border-box;
margin: 0 auto;
background: #fff;
border: 1px solid #BAB9C0;
padding: 0 40px;
.top_box{
width: 100%;
padding-bottom: 10px;
border-bottom: 1px solid #999997;
box-sizing: border-box;
text-align: center;
margin-top: 30px;
margin-bottom: 40px;
display: flex;
align-items: center;
justify-content: center;
.top_box div{
margin: 0 15px;
.top_box span{
font-size: 14px;
color: #5555E3;
cursor: pointer;
.title{
font-size: 16px;
font-weight: 600;
cursor: pointer;
.title span{
font-weight: 400;
font-size: 14px;
color: #C0B9B6;
.today{
color: #BAB9C0 !important;
cursor: text !important;
.title:hover{
color: #5555E3;
.item{
margin-bottom: 10px;
.item div{
font-size: 14px;
text-indent: 2em;
margin-top:4px;
.disnone{
display: none;
.main_hover{
color: #5555E3;
</style>
<div class="container">
<div class="top_box">
<span class="before">< 前一天</span><div>历史上的今天<span class="today"></div></span><span class="later">后一天 ></span>
</div>
<div class="items">
</div>
</div>
</body>
<script>
$(function(){
let milliscond = '';
let argumentsTime = '';
let todayTime = setTime().slice(5,)
$('.today').html('(' + todayTime + ')')
$('.before').click(function(){
let oneDay = 1000*60*60*24;
let before = milliscond - oneDay
let date = new Date();
date.setTime(before)
setTodaytime(date)
todayTime = todayTime.slice(5,)
$('.today').html('(' + todayTime + ')')
getHistorylist(argumentsTime)
$('.later').click(function(){
let oneDay = 1000*60*60*24;
let before = milliscond + oneDay
let date = new Date();
date.setTime(before)
setTodaytime(date)
todayTime = todayTime.slice(5,)
$('.today').html('(' + todayTime + ')')
getHistorylist(argumentsTime)
$(document).on('click','.item',function(){
let data = $(this).siblings();
for(let i = 0;i<data.length; i++){
$(data[i]).children().eq(-1).addClass("disnone")
if($(this).children().eq(-1).hasClass("disnone")){
$(this).addClass("main_hover").siblings().removeClass("main_hover");
$(this).children().eq(-1).removeClass("disnone");
}else{
$(this).removeClass("main_hover").siblings().removeClass("main_hover");
$(this).children().eq(-1).addClass("disnone");
$.ajax({
type: "GET",
url: "http://sahdfghjksfhjdksfhjd.seeyon1.server.wangserver.cn/history/getHistory?date=" + argumentsTime,
qcontentType: 'application/json',
dataType: "json",
success: res => {
let data = res.data
data = [{},{},{},{},{}]
let listHtml = '';
$.each(data, function(i, item) {
listHtml+= `<div class="item">
<p class="title">历史上的今天<span> (2022-08-22)</span></p>
<div class="disnone">新闻 [1] ,也叫消息、资讯,是通过报纸、电台、广播、电视台等媒体途径所传播信息的 [2] 一种称谓。是记录社会、传播信息、反映时代的一种文体。新闻概念有广义与狭义之分,就其广义而言,除了发表于报刊、广播、互联网、电视上的评论与专文外的常用文本都属于新闻之列,包括消息、通讯、特写、速写(有的将速写纳入特写之列)等等 </div>
</div>`
$('.items').html(listHtml)
});
function setTime(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth();
var date = now.getDate();
milliscond = now.getTime()
month = month + 1;
month = month.toString().padStart(2, "0");
date = date.toString().padStart(2, "0");
argumentsTime = `${year}-${month}-${date}`
var defaultDate = `${year}年${month}月${date}日`;
return defaultDate;
function setTodaytime(d){
milliscond = d.getTime()
var year = d.getFullYear();
var month = d.getMonth();
var date = d.getDate();
month = month + 1;
month = month.toString().padStart(2, "0");
date = date.toString().padStart(2, "0");
todayTime = `${year}年${month}月${date}日`
argumentsTime = `${year}-${month}-${date}`
</script>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
$(document).click(function(e){
if (!$(e.target).is('所点击的元素')){
var e = e || window.event;
var elem = e.target || e.srcElement;
while (elem) {
if (elem.classNa...
$("#id")[0].style.display = 'none';
$("#id")返回的是JQuery
它是个集合肯定没有display属性 $(“#firstStep”).hide(500);而且可以设置时间;(“#firstStep”).hide(500);而且可以设置时间;
$(“.class”).css(‘display’,’block’);
$(“#id”).show()表示display:block,
$(“#id”).hide()表示
$(".editTem_section").bind('click', function (e) {
e.stopPropagation();//调用停止冒泡方法,阻止document方法的执行
$('.templates').show()
$(document).bind('click', function () {
$('.templates').hide()
```html
<img src="图片路径" class="img-click">
<div class="content" style=";">隐藏内容</div>
jQuery部分:
```javascript
$(function(){
$(".img-click").click(function(){
$(this).next(".content").toggle();
解释一下代码的作用:
1. 首先给图片添加一个class为"img-click",并给隐藏内容添加一个class为"content";
2. 使用jQuery的click()方法来绑定图片的点击事件;
3. 使用next()方法获取图片下一个兄弟元素,也就是隐藏内容;
4. 使用toggle()方法来切换隐藏内容的显示和隐藏状态。
解决:npm run dev 报错`webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`????
萌新之路:
手把手教你git提交到码云(完整版)
weixin_38647584: