0

PHPを使用して.csvからhtmlテーブルを生成します。

私はこのJavaScript Livesearchを手に入れました.

これはコードです:

function doSearch() {
    var searchText = document.getElementById('searchTerm').value;
    var targetTable = document.getElementById('dataTable');
    var targetTableColCount;


    //Loop through table rows
    for (var rowIndex = 0; rowIndex < targetTable.rows.length; rowIndex++) {
        var rowData = '';

        //Get column count from header row
        if (rowIndex == 0) {
            targetTableColCount = targetTable.rows.item(rowIndex).cells.length;
            continue; //do not execute further code for header row.
        }

        //Process data rows. (rowIndex >= 1)
        for (var colIndex = 0; colIndex < targetTableColCount; colIndex++) {
            rowData += targetTable.rows.item(rowIndex).cells.item(colIndex).textContent;
        }

        //If search term is not found in row data
        //then hide the row, else show
        if (rowData.indexOf(searchText) == -1)
            targetTable.rows.item(rowIndex).style.display = 'none';
        else
            targetTable.rows.item(rowIndex).style.display = 'table-row';
    }

    function capitaliseFirstLetter(string)
    {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
}

検索では大文字の大文字と小文字が区別されます。とにかくエントリが見つかるように、それを無視したいと思います。

「jon doe」を検索すると、「jon doe」、「jon doe」、「jon doe」、「jon doe」などを見つけたいと思います。

これを既存のコードにどのように実装できますか?

4

1 に答える 1

1

たとえば、ToUpperCase を実行して文字列を比較できます。

var myName = 'Jon Doe';

次に、チェックしている名前に対して同じことを行います

var searchName = GetElementById("MyTextbox");

var areEqual = myName.toUpperCase() === searchName.toUpperCase();

それからあなたはすることができます

if(areEqual == True) {
    document.write("Names Match");
}
于 2013-10-29T12:26:52.620 に答える