2017-07-28 159 views
0

为什么自动完成输入框的工作任何人有任何想法解决它, 我的代码:Materializecss自动完成输入

<!DOCTYPE HTML> 

<html lang="en"> 

<head> 

<title>Site Name</title> 

<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css"> 

<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> 
</head> 

<body> 

    <nav class="blue"> 

    <div class="nav-wrapper"> 

     <a href="/index" class="brand-logo">Site Name</a> 

     <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a> 

     <ul class="right hide-on-med-and-down"> 

     <li><a href="/index">Index</a></li> 


     </ul> 

     <ul class="side-nav" id="mobile-demo"> 

     <li><a href="/index">Index</a></li> 

     </ul> 

    </div> 

    </nav> 
<br><br> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- 33 KB --> 

<style> 
.loader { 
    position: fixed; 
    left: 0px; 
    top: 0px; 
    width: 100%; 
    height: 100%; 
    z-index: 10; 
    background: url('/images/480.gif') 50% 50% no-repeat #fff; 
    opacity: 100%; 
} 
</style> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
<script type="text/javascript"> 
$(window).load(function() { 
setTimeout(function(){ 
    $('.loader').remove(); 
}, 3000); 
}); 
</script> 
<div class="loader"><center><br><br><br>Please Wait.<br></center></div> 

    <div class="row"> 
    <div class="col s12"> 
     <div class="row"> 
     <div class="input-field col s12"> 
      <i class="material-icons prefix">textsms</i> 
      <input type="text" id="autocomplete-input" class="autocomplete"> 
      <label for="autocomplete-input">Autocomplete</label> 
     </div> 
     </div> 
    </div> 
    </div> 
<br> 

<script src="//code.jquery.com/jquery-2.1.1.min.js"></script> 
<script src="//cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script> 
<script> 
$(".button-collapse").sideNav(); 
</script> 
<script> 
    $('.button-collapse').sideNav({ 
     menuWidth: 300, // Default is 300 
     edge: 'right', // Choose the horizontal origin 
     closeOnClick: true, // Closes side-nav on <a> clicks, useful for Angular/Meteor 
     draggable: true, // Choose whether you can drag to open on touch screens, 
     onOpen: function(el) { /* Do Stuff*/}, // A function to be called when sideNav is opened 
     onClose: function(el) { /* Do Stuff*/}, // A function to be called when sideNav is closed 
    } 
); 
</script> 
<script> 
    $('input.autocomplete').autocomplete({ 
    data: { 
     "Apple": null, 
     "Microsoft": null, 
     "Google": 'https://placehold.it/250x250' 
    }, 
    limit: 20, // The max amount of results that can be shown at once. Default: Infinity. 
    onAutocomplete: function(val) { 
     // Callback function when value is autcompleted. 
    }, 
    minLength: 1, // The minimum length of the input for the autocomplete to start. Default: 1. 
    }); 
</script> 
</body> 

</html> 

我tryed到很多方法,但没有结果,我也改变样式表的materializecss版本和脚本但再次没有工作,我也tryed其他自动完成,但不工作我试过这https://www.codexworld.com/autocomplete-textbox-using-jquery-php-mysql/但不工作与MaterializeCSS。

+0

你为什么要加载的jQuery **三次**? – DaveP

+0

DaveP我删除了所有,我离开只有一个,但再次不工作 –

回答

0

尝试添加此:

$(document).ready(function() { 
    [Your code here] 
}); 

它会等到页面被执行的代码之前完全加载。

另外,你有哪个版本的jquery?你说你删除了3个引用中的2个。

0

在materializecss自动完成下实施,希望这可以解决您的问题。

$(document).ready(function() { 
 

 
    $('input.autocomplete').autocomplete({ 
 
    data: { 
 
     "Apple": null, 
 
     "Microsoft": null, 
 
     "Google": 'https://placehold.it/250x250' 
 
    }, 
 
    limit: 20, // The max amount of results that can be shown at once. Default: Infinity. 
 
    onAutocomplete: function(val) { 
 
     // Callback function when value is autcompleted. 
 
    }, 
 
    minLength: 1, // The minimum length of the input for the autocomplete to start. Default: 1. 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css"> 
 
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script> 
 

 

 

 
<div class="row"> 
 
    <div class="col s12"> 
 
    <div class="row"> 
 
     <div class="input-field col s12"> 
 
     <i class="material-icons prefix">search</i> 
 
     <input type="text" id="autocomplete-input" class="autocomplete"> 
 
     <label for="autocomplete-input">Autocomplete</label> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>