07jquery的attr,hasClass,removeCla
作者:
An的杂货铺 | 来源:发表于
2019-03-11 15:10 被阅读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>Document</title>
<style>
.active {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<button>切换样式</button>
<div id="demo" class="one"></div>
<script src="./jquery-1.12.1.min.js"></script>
<script>
console.log($('#demo').attr('id'));
$('#demo').addClass('active');
$('button').on('click',function(){
if($('div').hasClass('active')){
$('div').removeClass('active');
}else{
$('div').addClass('active')
}
//$('div').toggleClass('active'); 或者直接使用toggleClass
})
</script>
</body>
</html>
本文标题:07jquery的attr,hasClass,removeCla
本文链接:https://www.haomeiwen.com/subject/fekbpqtx.html
网友评论