soyaine/JavaScript30

06-Type Ahead 添加一个判断内容是否为空的if

Opened this issue · 0 comments

问题

当清空输入框时 searchvalue 为空,此时所有诗句全部符合匹配规则,导致它们全部显示在页面中。

解决

displayMatches 函数开头添加一个判断,如果输入框为空不做处理:

if (!this.value) {
    return
}

位置

function displayMatches() {