[英]How to make your checkbox work with your Jquery functionality?
I have created 3 checkbox and i am struggling to make them to communicate with my Jquery button i have created to allow a user an option to select.我创建了 3 个复选框,我正在努力让它们与我创建的 Jquery 按钮进行通信,该按钮允许用户选择 select。 If one is selected and other one both are, they must when button is clicked should download my feeds as CSV file.如果一个被选中而另一个两个都被选中,他们必须在单击按钮时将我的提要下载为 CSV 文件。 I have the logic below i want to share for clear understanding as to what exactly i want to achieve.我想分享下面的逻辑,以便清楚地了解我想要实现的目标。
$(document).ready(function() { $("#download").click(function() { window.location.href = 'https://api.thingspeak.com/channels/899906/feeds.csv?start=2019-11-12%2019:11:12&end=2019-11-13%2019:11:13'; }); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="temperature"> <label class="custom-control-label" for="temperature">Temperature</label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="illuminance"> <label class="custom-control-label" for="illuminance">Illuminance</label> </div> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="button-state"> <label class="custom-control-label" for="button-state">Button-State</label> <.---Downloading File using Jquery with Buttons----> <div class="form-group"><br> <div class="col-md-1.9 text-center"> <button id="download" name="download" class="btn btn-warning">Download</button><br> </div> </div>
You want to initiate the download if at least two checkboxes are checked?如果至少选中了两个复选框,您想启动下载吗?
In that case, try using this:在这种情况下,尝试使用这个:
$(document).ready(function() {
$("#download").click(function() {
var count = 0;
if ($('#temperature').prop('checked')) count++;
if ($('#illuminance').prop('checked')) count++;
if ($('#button-state').prop('checked')) count++;
if (count > 1) {
window.location.href ='https://api.thingspeak.com/channels/899906/feeds.csv?start=2019-11-12%2019:11:12&end=2019-11-13%2019:11:13';
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.