当我输入文字并按回车键时,我希望文本框消失。但由于某些原因,当我输入';'时它才会消失。任何其他角色似乎都不起作用。
i
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private loginService:LoginService, private router:Router) { }
canActivate(next:ActivatedRouteSnapshot, state:RouterStateSnapshot) {
return this.loginService.isLoggedIn().map(e => {
if (e) {
return true;
}
}).catch(() => {
this.router.navigate(['/login']);
return Observable.of(false);
});
}
}
答案 0 :(得分:1)
只需删除不必要的eval
功能。
function enterPressed(e, field) {
if (e.keyCode == 13) {
var tb = document.getElementById("searchbox");
if (field.value.length > 0) {
document.getElementById('searchdisappear').style.display='none';
}
}
}
<!DOCTYPE html>
<html lang = "en">
<head>
<link rel="stylesheet" type="text/css" href="./css/main.css">
<script src ="./js/search.js"></script>
</head>
<body>
<!-- SEARCH BAR AND BUTTON -->
<div id="searchdisappear" style="display:block;">
<input id="searchbox" class="search" maxlength="200" type="text" onkeypress="enterPressed(event, searchbox)" placeholder="Search.."/>
<p class="searchtext" onclick="buttonClicked(searchbox)"
</div>
</html>