1. 程式人生 > >jQuery——切換toggle

jQuery——切換toggle

div utf char rip htm class jquery style ogg

toggle()-----顯示隱藏

toggleClass-------添加類或者刪除類

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.11.1.js"></script>
    <style>
        div {
            width: 100px;
            height
: 100px; border: 1px solid #ccc; } .box1 { margin-right: 10px; } .show { background-color: red; } </style> <script src="jquery-1.11.1.js"></script> <script> $(function () { $(
"button").click(function () { $(".box1").toggleClass("show"); }); }); </script> </head> <body> <button>切換</button> <div class="box1"></div> </body> </html>

jQuery——切換toggle