2017-07-05 5 views
0

をリダイレクト今から私に助けてくれてありがとう。は、私は、ユーザーが、それは特定のURLの例warning.htmlにリダイレクトされたスクリプトではありません単語を入力した場合、私は望んでいたオートコンプリートでスクリプトを持っていますが、私はあなたの場合は、それを行うことができないのですオートコンプリート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=UTF-8" /> 
 
<title>jQuery UI Autocomplete Testt</title> 
 
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> 
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
 
<script> 
 
\t $(document).ready(function() { 
 
\t \t var data = [ 
 
\t \t \t {label: 'Google', value: 'http://google.com'}, 
 
\t \t \t {label: 'Yahoo', value: 'http://yahoo.com'}, 
 
\t \t \t {label: 'BMW', value: 'http://bmw.com'}, 
 
\t \t \t {label: 'Bing', value: 'http://bing.com'} 
 
\t \t ]; 
 
\t \t 
 
    \t $("input#autocomplete").autocomplete({ 
 
\t \t \t source: data, 
 
\t \t \t focus: function (event, ui) { 
 
\t \t \t \t $(event.target).val(ui.item.label); 
 
\t \t \t \t return false; 
 
\t \t \t }, 
 
\t \t \t select: function (event, ui) { 
 
\t \t \t \t $(event.target).val(ui.item.label); 
 
\t \t \t \t window.location = ui.item.value; 
 
\t \t \t \t return false; 
 
\t \t \t } 
 
\t \t }); 
 
    \t }); 
 
    </script> 
 
</head> 
 
<body> 
 
<input id="autocomplete" /> 
 
</body> 
 
</html>

答えて

0

あなたはjqueryui 1.8を使用しています。私は以下の例で1.9を使用しています。 1.9に応答機能があるので、長さを確認できます。

<!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=UTF-8" /> 
<title>jQuery UI Autocomplete Testt</title> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<script> 
    $(document).ready(function() { 
     var data = [ 
      {label: 'Google', value: 'http://google.com'}, 
      {label: 'Yahoo', value: 'http://yahoo.com'}, 
      {label: 'BMW', value: 'http://bmw.com'}, 
      {label: 'Bing', value: 'http://bing.com'} 
     ]; 

     $("input#autocomplete").autocomplete({ 
      source: data, 
      focus: function (event, ui) { 
       $(event.target).val(ui.item.label); 
       return false; 
      }, 
      select: function (event, ui) { 
       $(event.target).val(ui.item.label); 
       window.location = ui.item.value; 
       return false; 
      }, 
      response: function(event, ui) { 
      if (ui.content.length === 0) { 
       console.log('action here'); 
      } 
     } 
     }); 
    }); 
    </script> 
</head> 
<body> 
<input id="autocomplete" /> 
</body> 
</html> 
関連する問題

 関連する問題