HTMLフォームとJavaScriptを使用して2D電話帳配列を作成しています
レコードの並べ替え、追加、削除などはできますが、ユーザー検索からレコードを返す方法がわかりません。
いくつかの方法を使用して、必要な電話帳エントリのインデックスを返すことができましたが、実際のエントリをユーザーに表示したいと考えています。
これはJavaScriptで可能ですか?簡単なはずなのに行き詰ってしまった!
これが私のコードです:
<html>
<head>
<title>Phone book</title>
<script>
myPhonebook = Array (
Array(' Robert Mory ',' 07554035121 '),
Array(' Susie Thompson ',' 0785430270 '))
document.write("<pre>")
for (j = 0 ; j < myPhonebook.length ; ++j)
{
for (k = 0 ; k < myPhonebook.length ; ++k)
document.write(myPhonebook[j][k])
document.write("<br />")
}
document.write("</pre>")
var search = function(){
var searchInput = document.getElementById('inputIdSearch').value
document.getElementById('searchResult').innerHTML =
("Searching for: " + searchInput + "...")
document.writeln(myPhonebook.indexOf('searchInput'))
</script>
</head>
<body>
<div id = "container">
<h2>Phonebook 1.0</h2>
<form name = "phonebookForm" id = "phonebookForm">
<h4 id ="search">Search Phonebook: <input type = "text" id="inputIdSearch" onblur="search()">
<span id="searchResult"></span></h4>
<h4 id ="input">Add entry: <input type = "text" id="inputIdInput"></h4>
<h4 id ="view">View all entries: <input type = "text" id="inputIdView"></h4>
</form>
</div>
</body>
</html>