点击选中效果

原创2019-08-07 09:01:0639
摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>选择效果</title>

<style>

li {

width: 100px;

height: 50px;

border: 1px salmon solid;

margin: 50px 30px 0px 0px;

padding: 0;

text-align: center;

line-height: 50px;

float: left;

list-style: none;

}

.active {

background: salmon;

}

</style>

</head>

<body>

<ul>

<li>1</li>

<li>1</li>

<li>1</li>

<li>1</li>

</ul>

</body>

<script src="./js/jquery-3.3.1.min.js"></script>

<script type="text/javascript">

$(function() {

$('li').click(function(){

if($(this).hasClass('active')){

$(this).removeClass('active')

}else{

$(this).addClass('active').siblings('li').removeClass('active')

}

})

})

</script>

</html>



发布手记

热门词条

第九期线上培训班