我是 Javascript 新手,打算编写一个函数,将数组中的所有字符串写入文档,该数组包含当前输入到输入文本字段中的字符串作为子字符串。
<!doctype html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<input type="text" >
<p></p>
<script>
var names = ["armadillo", "blue", "com", "demo", "engine"];
$("input").keypress(function() {
var incomplete = $( this ).val();
searchStrings();
};
function(searchStrings())
{
for(name in names)
{
if(name.indexOf(incomplete) != -1)
{
document.write(name);
} else
{
document.write("no match found");
}
}
};
});
</script>
</body>
</html>