gpt4 book ai didi

jquery - 延迟点击事件

转载 作者:行者123 更新时间:2023-12-01 08:33:57 24 4
gpt4 key购买 nike

每当我使用 on(click) 事件时,只有在访问另一个元素时才会注册单击。

$(".extensions").hide();
$('.outputs').on("touchstart click", function(e) {
var analogueOutputsVar = $("#AOUTP").val();
var onOffOutputsVar = $("#OOOUTP").val();
var cboxVar = $("#BOX");
var sumVar = parseFloat(analogueOutputsVar) + parseFloat(onOffOutputsVar);

if (sumVar > 8 || cboxVar.is(':checked')) {
$(".extensions").show()
} else {
$(".extensions").hide()
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
.content {
flex: 1 0 auto;
}
.footer {
flex-shrink: 0;
justify-content:center;
}

* {
box-sizing: border-box;
}
* {
box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 50%;
padding: 10px;
height: 30px; /* Should be removed. Only for demonstration */
}

/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}

input[type=number]{
width: 120px;
}
</style>
<div class="outputs">
<div class="row">
<div class="column">
ON/OFF Outputs
</div>
<div class="column">
<input type="number" name="OOOUTP" id="OOOUTP" min="0" step="1" max="28" value="0">
</div>
</div>
<div class="row">
<div class="column">
Analogue Outputs
</div>
<div class="column">
<input type="number" name="AOUTP" id="AOUTP" min="0" step="1" max="16" value="0">
</div>
</div>
</div>
<!---->
<div class="row">
<div class="column">
BOXTEST
</div>
<div class="column">
<input class="single-checkbox" type="checkbox" id="BOX" name="COM" value="BOX">
</div>
</div>
<!---->
<br />
<div class="extensions">
<legend>What feedback extensions do you need?</legend>
<div class="row">
<div class="column">
TEST1
</div>
<div class="column">
<input class="fb" type="number" name="TEST1" min="0" step="1" value="0">
</div>
</div>
<!---->
<div class="row">
<div class="column">
TEST2
</div>
<div class="column">
<input class="fb" type="number" name="TEST2" min="0" step="1" value="0">
</div>
</div>
<!---->
<div class="row">
<div class="column">
TEST3
</div>
<div class="column">
<input class="fb" type="number" name="TEST3" min="0" step="1" value="0">
</div>
</div>
</div>

https://jsfiddle.net/Colar/89g0onc2/5/ ,或者上面的代码片段显示了我正在谈论的确切问题。这个想法是,每当两个数字输入的总和大于 8 时,就会出现额外的选项。每当我单击复选框时,这些选项也应该出现。但是,每当我返回到数字输入时,似乎只会注册该复选框的单击。

有没有办法让 JQUery 识别单击复选框的单击,而无需返回?我想确保人们在没有看到选项的情况下不会点击下一步按钮。

最佳答案

怎么样this

Javascript

$(".extensions").hide();
$('.outputs').on("click", function(e) {
var analogueOutputsVar = $("#AOUTP").val();
var onOffOutputsVar = $("#OOOUTP").val();
var cboxVar = $("#BOX");
var sumVar = parseFloat(analogueOutputsVar) + parseFloat(onOffOutputsVar);

if (sumVar > 8 || cboxVar.is(':checked')) {
$(".extensions").show()
} else {
$(".extensions").hide()
}
});

HTML

<style>
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
.content {
flex: 1 0 auto;
}
.footer {
flex-shrink: 0;
justify-content:center;
}

* {
box-sizing: border-box;
}
* {
box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 50%;
padding: 10px;
height: 30px; /* Should be removed. Only for demonstration */
}

/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}

input[type=number]{
width: 120px;
}
</style>
<div>
<div class="row">
<div class="column">
ON/OFF Outputs
</div>
<div class="column">
<input class="outputs" type="number" name="OOOUTP" id="OOOUTP" min="0" step="1" max="28" value="0">
</div>
</div>
<div class="row">
<div class="column">
Analogue Outputs
</div>
<div class="column">
<input class="outputs" type="number" name="AOUTP" id="AOUTP" min="0" step="1" max="16" value="0">
</div>
</div>
</div>
<!---->
<div class="row">
<div class="column">
BOXTEST
</div>
<div class="column">
<input class="outputs" class="single-checkbox" type="checkbox" id="BOX" name="COM" value="BOX">
</div>
</div>
<!---->
<br />
<div class="extensions">
<legend>What feedback extensions do you need?</legend>
<div class="row">
<div class="column">
TEST1
</div>
<div class="column">
<input class="fb" type="number" name="TEST1" min="0" step="1" value="0">
</div>
</div>
<!---->
<div class="row">
<div class="column">
TEST2
</div>
<div class="column">
<input class="fb" type="number" name="TEST2" min="0" step="1" value="0">
</div>
</div>
<!---->
<div class="row">
<div class="column">
TEST3
</div>
<div class="column">
<input class="fb" type="number" name="TEST3" min="0" step="1" value="0">
</div>
</div>
</div>

说明:

我已从 div 中删除了类 outputs 并将其添加到 input 字段中,并且我还从选择器中删除了 touchstart 事件

关于jquery - 延迟点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59069227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com