我在输入上有一个onkey,但它找不到我在js文件中的函数。我在这里搜索了一些问题,但无法找到解决方案。
我的输入代码:
<input id="Name" type="text" name="name" class="form-control" onkeyup="autocomplet()">
<ul id="Name_list_id"></ul>
jQuery的:
function autocomplet() {
var min_length = 0;
var keyword = $('#Name').val();
if (keyword.length >= min_length) {
$.ajax({
url: "search.php",
type: "POST",
data: {keyword:keyword},
success:function(data){
$('#Name_list_id').show();
$('#Name_list_id').html(data);
}
});
} else {
$('#Name_list_id').hide();
}
}
function set_item(item) {
$('#Name').val(item);
$('#Name_list_id').hide();
}
教程的JS文件:
<script type="text/javascript" src="js/jquery.min.js">
</script> <script type="text/javascript" src="js/script.js"></script>
并在我的网站上:
<script src="s/jquery-2.1.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/events.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/jquery-ui.min.js"></script>
谢谢!
答案 0 :(得分:0)
<!DOCTYPE html>
<html>
<head>
<title>- jsFiddle demo by vilaskumkar</title>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/events.js" type="text/javascript"></script>
<!-- Add all you JS File in head -->
<!-- <link href="/css/result-light.css" rel="stylesheet" type="text/css"> -->
</head>
<body>
<form>
<input class="form-control" id="Name" name="name" onkeyup=
"autocomplet()" type="text">
</form>
<ul id="Name_list_id"></ul>
</body>
</html>