2

我一直在嘗試使用jQuery和JSP做自動完成,但到目前爲止,我無法得到隱藏字段值成功,我能夠拿到雖然該部門的名稱。jQuery的自動完成不能值傳遞給隱藏字段

有人能指出,究竟是什麼問題呢?

代碼

<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" /> 
    <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script> 
<script type="text/javascript" src="js/jquery.autocomplete.js"></script> 

<script type="text/javascript"> 
$(document).ready(function() { 
$("#dept").autocomplete( 
"myData.jsp", 
{ 
minChars:4, 
delay:30, 
autoFill:false, 
matchSubset:false, 
matchContains:1, 
selectOnly:1, 
select: function(event, ui) { 
$("#hid").val(result) 
} 
} 
); 

}); 

和myData.jsp我有//將移動代碼Servlet的

Department t = new Department();  
    String query = request.getParameter("q");  
    List<String> tenders = t.getDepartments(query); 

    Iterator<String> iterator = tenders.iterator(); 
    while(iterator.hasNext()) { 
     String deptName= (String)iterator.next(); 
     String depto = (String)iterator.next(); 
     out.println(deptName); 
    } 
+0

其中自動使用,你可以給我一個鏈接完整? – 2013-03-28 07:24:02

+0

@ M.I.T。我使用'jQuery的1.2.6.min.js'和 'jquery.autocomplete.js' – user75ponic 2013-03-28 07:28:35

+0

使用像'$( 「#藏」)VAL(ui.item.id);'或'$(」 #hid「)。val(ui.item.value);'無論你在使用 – 2013-03-28 07:33:27

回答

1

試試這個:

$("#dept").on('blur keyup change', function(){ 
    $("#hid").val($(this).val()); 
}); 

嘗試獲得事件blur keyupchange#dept文本輸入時得到這些事件#hid會得到它的價值。

+0

'$( 「#部門」)對( '模糊KEYUP變化',函數(){ $( 「#藏」)VAL($(本).VAL()); });'會一個單獨的功能?或者我應該更換這條線? '$(document).ready(function(){' – user75ponic 2013-03-28 07:19:53

相關問題