簡易復選框樣式設置
阿新 • • 發佈:2017-09-12
tar image css 11.2 input scrip ext col change
受這篇文章啟發 一大堆的 CSS 自定義復選框
主要是
<input type="checkbox" id="checkbox-1" /> <label for="checkbox-1">Check?</label> #checkbox-1 { display: none; } #checkbox-1 + label { color: red; } #checkbox-1:checked + label { color: blue; }
自己寫的
<head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="jquery-1.11.2.min.js"></script> <style type="text/css"> #checkbox-1 { display: none; } #checkbox-1 + label { background-image: url(check_null.png); background-position: 0 0; border: 0; background-size: 14px 14px; } #checkbox-1:checked + label { background-image: url(check_all.png); background-position: 0 0; border: 0; background-size: 14px 14px; } label { width: 14px; height: 14px; display: block; } </style> </head> <body> <input type="checkbox" id="checkbox-1" /> <label for="checkbox-1"></label> <script type="text/javascript"> $(‘#checkbox-1‘).change(function () { if($("#checkbox-1").is(‘:checked‘)) { console.log(‘abc‘) } }) </script> </body>
簡易復選框樣式設置