亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery之自動完成組件的深入解析

 更新時間:2013年06月19日 16:13:07   作者:  
本篇文章是對jQuery中的自動完成組件進行了詳細的分析介紹,需要的朋友參考下

簡單實例

復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AutocompleteOption</title>
<link rel="stylesheet" type="text/css" href="themes/base/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.widget.js"></script>
<script type="text/javascript" src="JS/jquery.ui.position.js"></script>
<script type="text/javascript" src="JS/jquery.ui.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 /* 初始化數(shù)據(jù)源 */
 var keys = ["jsp", "javascript", "jquery", "asp", "asp.net", "php",];

 $('#searchBox').autocomplete({
     source : keys,
  minLength : 2
 });
});
</script>
<style>
body{ padding:30px; }
</style>
</head>
<body>
<input id="searchBox" />
</body>
</html>


效果圖:

在上述代碼中,在頁面初始化的時候將頁面上的輸入框包裝成jQuery對象,然后使用autocomplete()方法將其包裝成自動完成組件,同時初始化其最小響應長度選項和數(shù)據(jù)源選項
2:自動完成組件的方法
有Search, Open, Focus, Select, Close, Change事件
復制代碼 代碼如下:

   function(event, ui) {
      //event: 觸發(fā)事件時的事件對象
    //ui, 是用戶界面對象,ui.item是一個包含label和value屬性的對象
  }

復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AutocompleteEvent</title>
<link rel="stylesheet" type="text/css" href="themes/base/jquery.ui.all.css"/>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.ui.core.js"></script>
<script type="text/javascript" src="JS/jquery.ui.widget.js"></script>
<script type="text/javascript" src="JS/jquery.ui.position.js"></script>
<script type="text/javascript" src="JS/jquery.ui.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 /*
  初始化數(shù)據(jù)源
 */
 var keys = ["c++", "c#", "c",
    "java", "j2ee", "jsp", "javascript", "jquery",
    "asp", "asp.net",
    "ruby", "vb.net",  "visual basic", "vb",
    "photo shop", "php",
    "flax", "flash"];
 function GetValues(key){
  var ks = [];

  if(key == "") return ks;  //如果關鍵字為空字符串,返回一個空集合

  for(var i = 0; i<keys.length; i++){
   if(keys[i].indexOf(key) == 0){
    ks[ks.length] = keys[i];
   }   
  }
  return ks;
 }

 $('#searchBox').autocomplete({
     source : [],
  search : function(event,ui){
   $('#searchBox').autocomplete(
    "option","source",GetValues($(this).val())
    );
  }
 });
});
</script>
<style>
body{padding-top:30px;}
td{ text-align:center; vertical-align:middle; padding:10px;}
#searchBox,#Search{ padding:2px; font-size:15px;}
#searchBox{width:220px;height:17px;}
#Search{width:80px;}
</style>
</head>
<body>
<table border="0" align="center">
<tr>
 <td colspan="2"><h1>My Search Engine</h1></td>
</tr>
<tr>
 <td><input id="searchBox" /></td>
 <td><button id="Search" >Search</button></td>
</tr>
</table>
</body>
</html>

效果圖:
  

相關文章

最新評論