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

base target="" specifies the target of the base link to open the frame

<base target=_blank> changes the target fram...

Two ways to implement HTML page click download file

1. Use the <a> tag to complete <a href=&...

Let's talk in depth about the principle and implementation of new in JS

Table of contents definition Constructor bodies a...

Weather icon animation effect implemented by CSS3

Achieve results Implementation Code html <div ...

Implementation steps for building FastDFS file server in Linux

Table of contents 1. Software Package 2. Install ...

Analysis of the principles of docker containers

Table of contents 01 What is the essence of a con...

How to use provide to implement state management in Vue3

Table of contents Preface How to implement Vuex f...

How to implement controllable dotted line with CSS

Preface Using css to generate dotted lines is a p...

An article tells you how to implement Vue front-end paging and back-end paging

Table of contents 1: Front-end handwritten paging...

Vue ElementUI implements asynchronous loading tree

This article example shares the specific code of ...

vue.config.js packaging optimization configuration

The information on Baidu is so diverse that it...

...