简体   繁体   中英

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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