<!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" /> <script language="JavaScript"> $(document).ready(function(){ var data=[{label:"中華電", value:"2412"}, {label:"中碳", value:"1723"}, {label:"台新金", value:"3045"}, {label:"台積電", value:"2330"}, {label:"台塑", value:"1301"}, {label:"創見", value:"2451"}, {label:"創意", value:"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<data.length; i++) { var match=reg.test(data[i].label) || reg.test(data[i].value); if (match) { var obj=new Object(); obj.label=data[i].label + ' (' + data[i].value + ')'; obj.value=data[i].value; result.push(obj); } } response(result); } }); }); </script> </body> </html>