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
Table of contents Functionalcomponents Childcompo...
Table of contents 1. Introduction to import_table...
This article describes how to build a MySQL maste...
Since my local MySQL version is relatively low, I...
Aggregate functions Acts on a set of data and ret...
The detailed installation process of mysql5.7.21 ...
Using the official MySQL image requires some modi...
The steps of docker packaging Python environment ...
This article example shares the specific code of ...
There is a table student in the mysql database, i...
1. Environmental Preparation 1.1 Basic Environmen...
Conclusion: In a multithreaded environment, if on...
The advantages of this solution are simplicity an...
Table of contents Rendering API changes Render fu...
1. Upper and lower list tags: <dl>..</dl...