如何检查和数组以及html表值之间的相等性

时间:2019-05-23 09:21:04

标签: javascript html

我检查数组值和html表单元格值之间的相等性是否相同,但是我该如何检查。我尝试这样做,但无法正常工作。如果值相同,则始终返回true。检查一下。。。

function addOrder() {

    var bookid = document.getElementById("book_id").value;
    var qty = document.getElementById("qty").value;
    var price = document.getElementById("unit_price").value;
    var total = document.getElementById("dts_total_price").value;


    var table = document.getElementById("results");

    var tableData = new Array();

    $('#results tr').each(function() {
        var row = $(this);
        tableData.push(row.find("TD").eq(0).html());

    });
    tableData.shift();


    var check;

    for (var i = 0; i <= tableData.length; i++) {
        var booksId = tableData[i];
        alert(bookid);
        if (bookid === booksId) {
            check = false;
        } else {
            check = true;
        }
    }

    alert(check);

    var table_len = (table.rows.length);
    var row = table.insertRow(table_len).outerHTML = "<tr id='row" + table_len + "'>" +
        "<td id='book_row" + table_len + "'>" + bookid + "</td>" +
        "<td id='qty_row" + table_len + "'>" + qty + "</td>" +
        "<td id='price_row" + table_len + "'>" + price + "</td>" +
        "<td id='total_row" + table_len + "'>" + total + "</td>" +
        "<td><input type='button' id='edit_button" + table_len + "' value='Edit' class='edit' onclick='edit_row(" + table_len + ")'>" +
        " <input type='button' id='save_button" + table_len + "' value='Save' class='save' onclick='save_row(" + table_len + ")'>   " +
        "<input type='button' value='Delete' class='delete' onclick='delete_row(" + table_len + ")'></td></tr>";
    document.getElementById("qty").value = "";
    document.getElementById("unit_price").value = "";
    document.getElementById("dts_total_price").value = "";

};

0 个答案:

没有答案