简体   繁体   English

如何启用和禁用下一个和上一个按钮?

[英]How to enable and disable the next and previous buttons?

I have a table which contains a button. 我有一个包含按钮的表。 This button gives the details of a particular row in a modal box, and this modal box helps the user to go to next and previous from the table. 此按钮在模式框中提供特定行的详细信息,此模式框可帮助用户从表中移至下一个和上一个。 Next will give information of next value of table and previous will give the previous value of row of table. 下一个将给出表的下一个值的信息,上一个将给出表的行的前一个值。 I have almost written code for that, but once I reach to the end of table the next button disables and while clicking previous it should be enabled again but it remains disabled. 我几乎为此编写了代码,但是一旦到达表格末尾,下一个按钮将被禁用,单击上一个按钮时应再次将其启用,但仍保持禁用状态。

Here the code below. 这里的代码如下。

$('#review_essay').delegate('.navBtn', 'click', function () {
    var current_row_id = $(this).parents('#review_essay').attr('current_row_id');
    var position_value = $(this).attr('position_value');
    var navValue = parseInt(current_row_id) + parseInt(position_value);
    alert(current_row_id)
    alert(position_value)
    alert(navValue)
    if (current_row_id <= 0)
    {
        alert(current_row_id)
        $("#btn2").attr('disabled', true);
        $("#btn1").attr('disabled', false);
    }
    else
    {
        $("#btn2").attr('disabled', false);
    }
    if (current_row_id < last_value) {
        var navValue = parseInt(current_row_id) + parseInt(position_value);
    }
    else
    {
        $("#btn1").attr('disabled', true);
        alert('End of the row, click back for previous data');
    }

    var qid = $('#essay_data').find('tbody').find('tr').eq(navValue - 1).attr('qid');
    alert(qid);
    var uid = $('#essay_data').find('tbody').find('tr').eq(navValue - 1).attr('uid');
    var paper_id = $('#essay_data').find('tbody').find('tr').eq(navValue - 1).data('paper_id')
    var session_id = $('#exam_details').attr('session_id')
    var exam_id = $('#exam_details').attr('exam_id')
    //alert('reached');
    navigate(exam_id, session_id, paper_id, qid, uid);
});

if you getting object of current row like 如果您得到当前行的对象

current_row_object=$(this);<br>

Then you can get next and previous row object like. 然后就可以得到下一个和上一个行对象。

next_row_obj=$(this).next("tr");<br>
previous _row_obj=$(this).prev("tr");<br>

if($(next_row_obj).length)<br>
 $("#nextbtn").attr('disabled', true);<br>
else<br>
 $("#nextbtn").attr('disabled', false);<br>


if($(previous _row_obj).length)<br>
 $("#prevBtn").attr('disabled', true);<br>
else<br>
 $("#prevBtn").attr('disabled', false);<br>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM