During the front-end development process, a situation occurred where a check box was required. For the convenience of user operation, the click event was placed on the DIV. (knockout.js is used in this) The code is roughly as follows: Copy code The code is as follows:<div id="one" data-bind="click:clickevent"> <input type="checkbox"><span>Please check me if you have any questions</span> </div> But a strange phenomenon occurred when writing it this way. Everything was normal when clicking the div with the mouse. But it is not normal to directly check the checkbox with the mouse: The checkbox is in the unchecked state. Click the checkbox with the mouse to check it. What should be achieved at this time is: 1. Execute the clickevent event of div; 2. After the event is executed, the checkbox is in the checked state. But the end result is that the checkbox is still unchecked. The result of tracking and debugging is that when the clickevent event is executed, the checkbox is still in the checked state, but after the clickevent is executed, the jquery code is executed, and after two or three steps, the checkbox is changed to the unchecked state. The reason has not been found yet. (A similar situation also occurs with the radiobox used in another place) There is no other way, so I have to work around it. I cover the checkbox with a div so that when the mouse clicks, it clicks the div instead of the checkbox, and changes the checkbox state through clickevent (the clickevent already has code to change the checkbox state) The implementation is as follows: Copy code The code is as follows:<div id="one"> <div id="two" data-bind="click:clickevent"></div> <div id="three"> <input type="checkbox"/> <span>Please check me if you have any questions</span> </div> </div> The two divs with IDs two and three need to set two properties: position: absolute; z-index: 1; The z-index attribute of the div on the upper layer is larger than that of the div on the lower layer. The ID attribute of DIV above is just for illustration. Generally, the class attribute is used in the program. |
<<: Detailed explanation of the code for implementing linear gradients with CSS3
>>: MYSQL's 10 classic optimization cases and scenarios
1. Big Data and Hadoop To study and learn about b...
This article example shares the specific code of ...
First of all, you need to understand why you use ...
Table of contents 1. Comments on MySQL primary ke...
Table of contents MAH 1. Introduction to MAH Arch...
Table of contents 1. System environment 2. Operat...
There are two ways: 1. Service method Check the f...
Table of contents Declare fonts with font-face co...
x-ua-compatible is used to specify the model for ...
Table of contents Setting up a basic HTTP request...
Table of contents Basic HTML structure Generate s...
Preface Recently, I added two fields to a table i...
This time, we will try to package the running con...
1. Pull the image docker pull registry.cn-hangzho...
Use CSS3 to achieve cool radar scanning pictures:...