<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery UI 測試</title> <script src="jquery.min.js"></script> <script src="jquery-ui.min.js"></script> <link id="theme" href="themes/hot-sneaks/jquery-ui.min.css" rel="stylesheet"> <style> body {font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;} </style> </head> <body> 股名 (輸入 "中","台","創") : <input id="auto1" type="text" /> 股號 (輸入 "1","2","3") : <input id="auto2" type="text" /> <script language="JavaScript"> $(document).ready(function(){ var stock_name=["中華電","中碳","台新金","台積電","台塑","創見","創意"]; var stock_id=["2412","1723","3045","2330","1301","2451","3443"]; $("#auto1").autocomplete({source: function(request, response) { var term=request.term; var result=new Array(); var reg=new RegExp("^" + term,"i"); //以 term 開頭者 for (var i=0; i<stock_name.length; i++) { var match=reg.test(stock_name[i]); if (match) {result.push(stock_name[i]);} } response(result); } }); $("#auto2").autocomplete({source: function(request, response) { var term=request.term; var result=new Array(); var reg=new RegExp("^" + term,"i"); //以 term 開頭者 for (var i=0; i<stock_id.length; i++) { var match=reg.test(stock_id[i]); if (match) {result.push(stock_id[i]);} } response(result); } }); }); </script> </body> </html>