<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="box">
文字内容
</div>
</body>
<script type="text/javascript">
$(function(){
var $btn=true
$(".box").click(function(){
if($btn){
$(this).css("background","#00FF00")
$btn=false
}else{
$(this).css("background","#fff")
$btn=true
}
})
})
</script>
</html>
<!DOCTYPE html><html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="jquery-3.2.1.min.js"></script>
<style>
p{
padding:10px
border:1px solid #cccccc
display: block
}
</style>
</head>
<body>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
</body>
</html>
<script>
$(document).ready(function(){
$("p").click(function(){
$("p").css("background-color","#fff")
$(this).css("background-color","#ff6600")
})
})
</script>
问题:怎么写能点击a标签这个a标签高亮(变色或者加粗之类的)
解答:这需要用到js,代码如下
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
<script type="text/javascript" src="../resources/js/jquery.min.js"></script>
<style>
a{cursor:pointer}
a:hover{color:green}
a.active{color:red}
</style>
</head>
<body>
<a class="active">我是a1</a>
<a>我是a2</a>
<a>我是a3</a>
<a>我是a4</a>
<script>
$("a").click(function(){
$(this).addClass("active").siblings().removeClass("active")
})
</script>
</body
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)