簡體   English   中英

我需要根據另一個 API 的值檢查一個 API 中的預加載復選框,我該怎么做?

[英]I need to Check the preloaded checkbox from one API based on the Value of Another API, How can I do that?

      HTML;
    
                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <meta http-equiv="X-UA-Compatible" content="IE=edge">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>Document</title>
                          
                </head>
                <body>
                    <table id="Table1" class="table table-bordered table-hover">
                        <thead>
    <tr>
    <th>List</th>
    <th>Push Notification&nbsp;&nbsp;&nbsp;<input type='checkbox'  name='all_push' id='all_push' class='all_push' /></th>
    <th>SMS&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_sms' id='all_sms' class='all_sms' /></th>
    <th>Call&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_call' id='all_call' class='all_call' /></th>
    <th>Email&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_email' id='all_email' class='all_email' /></th>
    </tr>            
    
    </thead>
    <tbody>
    <tbody>
    </table>
    </body>
    </html>
    
    JS;
            
    Here I have to do two things, first I have to fetch the checkboxes which I have access, from one API . Then I have to check the checkboxes based of another API value .
            
    Here I fetched the check boxes from the API,
            
    function getlist(t, e) {
                    
    $.ajax({
    type: "GET",
    url: base_api_url,
    dataType: "json",
                        success: function (t) {         
                            
                            t.length > 0 ? $.each(t, function (t, a) {
                                    var push_notif_checked = push_notif_disabled = '';
                                    var sms_checked = sms_disabled = '';
                                    var call_checked = call_disabled = '';
                                    var email_checked = email_disabled = '';
                                    if(a.push_notification == 'No') {
                                        push_notif_disabled = 'disabled';
                                    }
                                    if(a.sms == 'No') {
                                        sms_disabled = 'disabled';
                                    }
                                    if(a.call == 'No') {
                                        call_disabled = 'disabled';
                                    }
                                    if(a.email == 'No') {
                                        email_disabled = 'disabled';
                                    }
                                    
          e += "<tr class='extra_rows'><td>" Mobile "</td><td><input type='checkbox'id='push_notification' class='push_notification'/></td><td><input type='checkbox'  class='sms' /></td><td><input type='checkbox'  class='call' /></td><td><input type='checkbox'  class='email' /></td></tr>"
                                }) :e="<tr class='extra_rows'><td colspan='2'>No data found.</td></tr>",
                                $("#Table1").append(e)
                        },
                        error: function () {
                            toastr.error("Something went wrong ")
                        }
                    })
                };

    

現在我必須制作另一個 Ajax 來檢查基於 Json 結果的復選框,

例如考慮我的 JSON 結果格式如下,

{ "Phone_list":"不需要", "Push_notif":"是", "Sms_notif":"否", "Call_notif":"是", "Email_notif":"否" },

如果 Push_notif 的 JSON 值為“是”,我需要檢查推送通知的復選框,同樣我該如何為 SMS、Call、Email 執行此操作,基於 Z0ECD11C1D7A287401D148A23BBD7A2 的結果如上所示同時,有人可以幫助我嗎?

要檢查復選框,您需要在 jquery 中使用它

.checkboxClass => 這是 class 復選框的名稱

$('.checkboxClass').prop('checked', true);

for un check $('.checkboxClass').prop('checked', false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM