2011-11-25 87 views
1

從來就下面的JavaScript功能:的JavaScript自動完成功能的href

<script type="text/javascript"> 

    $(function() { 
     var data = (<?php include("php/search_new.php"); ?>).Data.Recipes; 
     var source = []; 
     for (var i in data) { 
      source.push({"href": "/php/get_recipe_byID.php?id=" + data[i].ID, "label": data[i].TITLE}); 
     } 
     $("#searchrecipes").autocomplete({ 
      minLength: 3, 
      source: source, 
      select: function(event, ui) { 
       window.location.href = ui.item.href; 
     } 
    }); 
}); 

    </script> 

<input id="searchrecipes" type="text" name="searchrecipes" style="margin-left: 850px; margin-top: 0px; width:170px; background: #fff url(images/search_icon.png) no-repeat 100%;" onblur="this.style.background='#ffffff'; background: #fff url(images/search_icon.png) no-repeat 100%;" onfocus="this.style.background='#c40606'; background: url(images/search_icon.png) no-repeat 100%;" placeholder="Suchen..."></input> 
       <input type="submit" name="buttonsenden" style="display:none;" value="" width: 5px></input> 

功能已經工作,但它突然停止工作。問題是,下拉自動完成的href不可點擊。

var data = ({"Data":{"Recipes":{"Recipe_5":{"ID":"5","TITLE":"Spaghetti Bolognese"},"Recipe_7":{"ID":"7","TITLE":"Wurstel"},"Recipe_9":{"ID":"9","TITLE":"Schnitzel"},"Recipe_10":{"ID":"10","TITLE":null},"Recipe_19":{"ID":"19","TITLE":null},"Recipe_20":{"ID":"20","TITLE":"Hundefutter"},"Recipe_26":{"ID":"26","TITLE":"Apfelstrudel"},"Recipe_37":{"ID":"37","TITLE":null},"Recipe_38":{"ID":"38","TITLE":"AENDERUNG"},"Recipe_39":{"ID":"39","TITLE":null},"Recipe_40":{"ID":"40","TITLE":"Schnitzel"},"Recipe_42":{"ID":"42","TITLE":"Release-Test"},"Recipe_43":{"ID":"43","TITLE":"Wurstel2"}}},"Message":null,"Code":200}).Data.Recipes; 

所有必需的jQuery腳本都可用。 有什麼問題?

+0

zIndex對重疊的東西? – mplungjan

回答

0

爲什麼不直接使用遠程源,而不是做這個數組的作品? 這並不是使用PHP和JS在一起的方法:你可以直接使用遠程源

var data = (<?php include("php/search_new.php"); ?>) 

。這將通過一個AJAX請求被加載:

$(function() { 
     $("#searchrecipes").autocomplete({ 
      minLength: 3, 
      source: "/php/recipe_index.php", 
      select: function(event, ui) { 
       window.location.href = ui.item.href; 
      } 
    }); 

參見Documentation "source:" parameterdemo-implementation (view sourcecode)

乾杯。弗蘭克