【问题标题】:Disable just one button out of set buttons仅禁用设置按钮中的一个按钮
【发布时间】:2018-11-28 08:51:32
【问题描述】:

我编写了表创建 PHP 代码,它使用名为 job_list 的 mysql 表中的数据创建表。表格的每一行都有一个按钮供用户选择作业。

我的问题是,我只想禁用所有按钮中的一个按钮。我尝试使用一个禁用所有这些的类。然后我遇到了另一个解决方案here,这是我想要的,但问题是,每次我第一次单击按钮时都必须单击两次才能使代码正常工作。在初始点击代码开始按预期工作后。

这是我的 PHP + HTML 代码

<div class="limiter">
    <div class="container-table100">
        <div class="wrap-table100">
            <div class="table">

                <div class="row header">
                    <div class="cell topLeft">
                        Customer Name
                    </div>
                    <div class="cell">
                        Target
                    </div>
                    <div class="cell">
                        File Type
                    </div>
                    <div class="cell">
                        Job Comment
                    </div>
                    <div class="cell">
                        Cust. ID
                    </div>
                    <div class="cell topRight">
                        Select Job
                    </div>
                </div>

                <?php while ($getJobsRow = $getJobs -> fetch(PDO::FETCH_ASSOC)){ ?>
                    <?php $loopCount++; //Count the loop run through time ?>
                <div class="row">
                    <div class="cell left <?php if ($numOfRows == $loopCount){ ?>bottomLeft<?php } //Set the CSS class if the loop is at the last row ?> " data-title="Full Name">
                        <?php echo $getJobsRow['customer_name']; ?>
                    </div>
                    <div class="cell" data-title="Age">
                        <?php echo $getJobsRow['Mal_Name']; ?>
                    </div>
                    <div class="cell" data-title="Job Title">
                        <?php echo $getJobsRow['FileExt']; ?>
                    </div>
                    <div class="cell" data-title="Location">
                        <?php echo $getJobsRow['Job_Comment']; ?>
                    </div>
                    <div class="cell" data-title="Location">
                        <?php echo $getJobsRow['customer_id']; ?>
                    </div>
                    <div class="cell right <?php if ($numOfRows == $loopCount){ ?>bottomRight<?php } ?> " data-title="Location">
                        <button id="selBtnId_<?php echo $getJobsRow['jId']; ?>" class="selJobBtn w3-btn w3-blue-dark w3-round-medium w3-ripple" data-jid="<?php echo $getJobsRow['jId']; ?>">Select</button>
                    </div>
                </div>
                <?php } ?>

            </div>
        </div>
    </div>
</div>

我的 JQuery,

$(document).ready(function () {
    $('.selJobBtn').on('click', function () {
        $.ajax({
            url: '../Functions/OpenjobLister_Function.php',
            type: 'get',
            data: {
                'jid':$(this).data('jid'),
                'uid':$('#uId').val()
            },
            dataType:'text',
            complete:function(data){
                if(data.responseText !== "1"){
                    alert("Data not added");
                }else{
                    disableSelBtn();
                }
            }
        });            
    });
});

function disableSelBtn() {
    const $selBtns = $("button[id*='selBtnId_']");

    $selBtns.on('click', function () {
        $(this).prop('disabled', true);
    })
}

我使用 AJAX 来发送和接收数据。我只想在数据提交成功时禁用按钮。所以有人可以告诉我如何在第一次使用时只需单击一次而不必单击两次。如果有更好的方法,请告诉我。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:
    $(document).ready(function () {
    $('.selJobBtn').on('click', function () {
        var thisButton = this;
        $.ajax({
            url: '../Functions/OpenjobLister_Function.php',
            type: 'get',
            data: {
                'jid':$(this).data('jid'),
                'uid':$('#uId').val()
            },
            dataType:'text',
            complete:function(data){
                if(data.responseText !== "1"){
                    alert("Data not added");
                }else{
                    $(thisButton).prop('disabled', true);
                    //disableSelBtn();
                }
            }
        });            
    });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2021-10-08
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多