サマリー:<!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">
<script type="text/javascript"src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<title>jQuery事件切換</title>
<style type="text/css">
div,p{width: 200px;height: 200px;border: 1px solid #ccc;}
</style>
</head>
<body>
<script type="text/javascript">
// hover(over,out)
// over:鼠標(biāo)移上元素上要觸發(fā)的一個(gè)函數(shù)
// out:鼠標(biāo)移出元素上要觸發(fā)的一個(gè)函數(shù)
$(document).ready(function(){
// $('div').hover(
// function(){
// $(this).css('background','red')
// },
// function(){
// $(this).css('color','#fff')
// }
// )
// toggle() 如果元素是可見(jiàn)的,就切換為隱藏,否則相反
$('button').click(function(){
$('p').toggle().css('background','red')
})
})
</script>
<div>我是內(nèi)容</div>
<p style="display: none;"></p>
<button>點(diǎn)擊</button>
</body>
</html>
添削の先生:天蓬老師添削時(shí)間:2019-01-27 14:05:07
先生のまとめ:$('p').toggle().css('background','red'), 如果這行代碼不用jquery , 想過(guò)應(yīng)該怎么寫(xiě)嗎?