我想在用户点击文本框时显示供应商名称。因为我正在使用jquery.autocomplete.js。我正在关注this tutorial
我的代码在jsp中
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script src="js/jquery.autocomplete.js"></script>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<style>
input {
font-size: 120%;
}
</style>
</head>
<body>
<span class="label">Supplier Name</span>
<span class="ib"> <input type="text" name="supplierId" id="supplierId"/></span>
<script>
$("#supplierId").autocomplete("autoCompleteSupplier");
</script>
</body>
</html>
struts.xml中的
<action name="autoCompleteSupplier" class="iland.supplier.SupplierAction" method="autoComplete">
<result name="success">/pages/supplier/suggestion.jsp</result>
<result name="input">/pages/supplier/suggestion.jsp</result>
<result name="login">/pages/login.jsp</result>
</action>
在动作类
中public class SupplierAction extends ActionSupport {
private String q;//getter and setter method
public String autoComplete() {
System.out.println("->SupplierAction autoComplete()");
System.out.println(getQ());
SupplierBusiness cb = new SupplierBusiness();
Map data = cb.autoComplete(getQ());
setSupplierList((ArrayList) data.get("supplierList"));
return SUCCESS;
}
}
autocompte应显示在jsp页面
之后<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<s:iterator value="supplierList" var="suplst">
<s:property value="supplierId"/>
<s:property value="supplierName"/>
</s:iterator>
在使用crome检查时,它显示以下错误
Uncaught SyntaxError: Unexpected end of input jquery.autocomplete.js:462
Uncaught Error: cannot call methods on autocomplete prior to initialization;
attempted to call method 'autoCompleteSupplier' jquery-1.9.1.js:507
答案 0 :(得分:0)
两件事:
autocomplete
放入您的DOM就绪函数中,例如,在HTML的末尾。source
属性设置操作。使用完整的网址,例如来自<s:url>
标记。<script>
$(function() {
source: "<s:url action='autoCompleteSupplier'/>"
});
</script>
请注意,此功能已包含在Struts 2 jQuery plugin。
中