How to use custom images in Html to display checkboxes

How to use custom images in Html to display checkboxes

If you need to use an image to implement the use of a checkbox, you can use it to implement it. The implementation principle is to replace the display of the checkbox with a label, set the display of the checkbox to none, use the image img to be displayed in the label tag, and then use a js function to control the switching of the image whether it is selected or not.

JavaScript CodeCopy content to clipboard
  1. <label for = "agree" >
  2. <img class = "checkbox" alt = "checked" src = "../img/checked.png" id = "checkimg" onclick = "checkclick();" >
  3. </label>
  4. <input type= "checkbox" style= "display:none" id= "agree" checked= "checked" >
  5. <script>
  6.           function checkclick(){
  7.              var checkimg = document.getElementById( "checkimg" );
  8.              if ($( "#agree" ).is( ':checked' ) ){
  9. $( "#agree" ).attr( "checked" , "unchecked" );
  10. checkimg.src = "../img/unchecked.png" ;
  11. checkimg.alt= "unchecked" ;
  12. } else {
  13. $( "#agree" ).attr( "checked" , "checked" );
  14. checkimg.src = "../img/checked.png" ;
  15. checkimg.alt= "check" ;
  16. }
  17. }
  18. </script>

The above is all the content of the method of using custom images in Html to realize checkbox display. I hope everyone will support 123WORDPRESS.COM~

<<:  MySQL transaction analysis

>>:  Implementation of CSS circular hollowing (coupon background image)

Recommend

Specific use of MySQL segmentation function substring()

There are four main MySQL string interception fun...

Detailed explanation of Vue's simple store

The simplest application of store in Vue is globa...

JS achieves five-star praise case

This article shares the specific code of JS to ac...

Detailed explanation of XML syntax

1. Documentation Rules 1. Case sensitive. 2. The a...

The difference between GB2312, GBK and UTF-8 in web page encoding

First of all, we need to understand that GB2312, ...

Docker custom network detailed introduction

Table of contents Docker custom network 1. Introd...

Use CSS to set the width of INPUT in TD

Recently, when I was using C# to make a Web progra...

Zen coding for editplus example code description

For example, he enters: XML/HTML Code div#page>...

Using Docker run options to override settings in the Dockerfile

Usually, we first define the Dockerfile file, and...

Cross-browser development experience summary (I) HTML tags

Add a DOCTYPE to the page Since different browser...

Perfect solution for JavaScript front-end timeout asynchronous operation

Table of contents What happens if a piece of code...

Detailed example of IOS database upgrade data migration

Detailed example of IOS database upgrade data mig...

Optimization analysis of Limit query in MySQL optimization techniques

Preface In actual business, paging is a common bu...