Jquery OR operator not working

时间:2015-06-15 14:36:13

标签: javascript php jquery

The function below doesn't seem to work and I can't tell if my query is wrong or my php. $num_rows returns a value of 3 in a previous php script on the same page.

$('.markTD').click(function () {
    var qnum = $(this).attr('value');
    if (qnum != 1 || qnum != <?php echo $num_rows ?> ) {
        $('#submit').css("display", "none");
        $('#next').css("display", "block");
        $('#prev').css("display", "block");
    }
});

1 个答案:

答案 0 :(得分:0)

You should convert the input value from string to number, like below.

Oh, and use .val() function instead of .attr('value') :)

$('.markTD').click(function () {
    var qnum = parseInt($(this).val() || 0, 10);
    if (qnum != 1 || qnum != <?php echo $num_rows ?> ) {
        $('#submit').css("display", "none");
        $('#next').css("display", "block");
        $('#prev').css("display", "block");
    }
});