checkbox去掉默認樣式添加新樣式及點擊事件


 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>checkbox樣式</title>
    </head>
    <style>
        .remberpass input,
        .remberpass span {
            float: left;
        }
        /* 將瀏覽器默認的checkbox樣式重置 */
        
        input[type=checkbox] {
            -webkit-appearance: none;
            width: 15px;
            height: 15px;
            background-color: white;
            border: 1px solid #5692fc;
            border-radius: 3px;
        }
        
        input[type=checkbox]:checked {
            background: red;/*可加背景圖片*/
            background-repeat: no-repeat;
        }
    </style>

    <body>
        <div class="remberpass">
            <input class="test" type="checkbox" />
            <span>記住密碼</span>
        </div>
    </body>
</html>
<script src="https://cdn.bootcss.com/jquery/1.12.3/jquery.min.js"></script>
<script>
    $(".test").click(function(){
        if($("input[type='checkbox']").prop('checked')){
            alert("選中");
        }else{
            alert("未選中")
        }
    })
        
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM