我的应用程序中有一个自动完成输入字段。当带有此自动完成输入字段的 jsp 打开时,我'names' is undefined
在行中出现错误<body onload="getNames(names)">
。这仅在 IE8、7、9 中发生。在 Chrome 和 Firefox 中,一切都很好。在控制器中,我获取用户的姓名和姓氏并将它们写在一个分隔的字符串中$
,然后将该字符串发送allUsersRoleUserAC
到 jsp。方法 getNames(names) 拆分该字符串并将它们放入 var tags
。
这是jsp代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin page</title>
<link rel="stylesheet" type="text/css" href="<%=response.encodeURL(request.getContextPath() + "/css/jquery-ui.css") %>" />
<link rel="Stylesheet" type="text/css" href="<%=response.encodeURL(request.getContextPath() + "/css/DOMAlert.css") %>" media="screen" />
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/DOMAlert.js") %>"></script>
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/jquery-1.8.2.js") %>"></script>
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/jquery-ui.js") %>"></script>
<script type="text/javascript">
var tags = new Array();
function getNames(names){
tags = names.value.split('$');
}
</script>
</head>
<body onload="getNames(names)" >
<form action="<%=response.encodeURL(request.getContextPath() + "/admin/deleteUser.html") %>" method="post">
<input id="names" type="hidden" value="${ requestScope['allUsersRoleUserAC'] }" />
<input name="korisnik" class="userSelectDeleteUser" value="ime prezime" onclick="this.value=''" id="autocomplete" />
<input class="izbrisiKorisnikaButtonPosition" id="buttonRightPart" type="button" value="Izbriši" />
</form>
<script type="text/javascript">
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
</body>
</html>