简体   繁体   English

如何使您的复选框与您的 Jquery 功能一起使用?

[英]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.

相关问题 如何让Jquery在页面的某个区域展开div? - How to make Jquery expand a div on a certain area of your page? 如何实现复选框的属性以在不使用Grid对象或jQuery.Data(Input)的情况下跟踪表中每一行的更改? - How to implement properties of checkbox to keep track of your changes on each line in your table without employing Grid object or jQuery.Data(Input)? 如何管理您网站上的jQuery库? - How to manage your jQuery library in your web site? 如何使 Sweetalert 适用于您的按钮 - How to make sweetalert works for your button 如何使画布中的内容具有响应性? - How to make the content in your canvas responsive? 如何让你的代码等待循环的执行 - How to make your code wait for execution of loop 如何使您的 Discord Bot 始终处于活动状态 - How to make your Discord Bot always active 受保护的内容-如何使右键单击和F12在您的网站上不起作用? - Protected Content - How to make the Right-Click and F12 don't work in your website? 如何制作:hover 在手机屏幕上拖动手指即可工作? - How to make :hover work on mobile if you drag your finger across the mobile screen? 您如何制作整个OWN语言编码器? 我试过了..(不起作用) - How Do You Make Your Entire OWN Language Coder? I Tried This.. (doesn't work)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM