mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-25 01:19:45 +00:00
If the user clicked directly on the input inside a label, then it already received a click event. Dispatching a second one via the label is redundant, and means that if the input is a checkbox, it gets its value toggled twice.
51 lines
1.1 KiB
HTML
51 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
}
|
|
|
|
.box {
|
|
display: inline-block;
|
|
width: 100px;
|
|
height: 100px;
|
|
background-color: purple;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
width: 200px;
|
|
height: 200px;
|
|
border: 1px solid black;
|
|
}
|
|
</style>
|
|
<script src="../include.js"></script>
|
|
<body>
|
|
<form>
|
|
<label>
|
|
<input type="checkbox" id="radio1" class="target">
|
|
</label>
|
|
<label>
|
|
<input type="checkbox" id="radio2" class="target">
|
|
</label>
|
|
<input type="checkbox" id="done">
|
|
</form>
|
|
</body>
|
|
<script>
|
|
asyncTest(done => {
|
|
document.querySelectorAll('.target').forEach(function (element) {
|
|
element.addEventListener('click', function (event) {
|
|
println(`click event on input#${event.target.id}`);
|
|
});
|
|
});
|
|
|
|
document.getElementById('done').addEventListener('click', function (event) {
|
|
done();
|
|
});
|
|
|
|
internals.click(5, 10);
|
|
internals.click(5, 210);
|
|
internals.click(5, 410);
|
|
});
|
|
</script>
|
|
</html>
|