1.代码(普通版)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<select class="js-data-example-ajax" style="width: 929px;"></select>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script type="text/javascript">
//select框联想
/**
* placeholder:初始默认的填充内容
* minimumInputLength:开始搜索所需的最少字符数
* **/
$(".js-data-example-ajax").select2({
placeholder: 'Search for a repository',
minimumInputLength: 1,
ajax: {
delay: 250,
url:'https://api.github.com/search/repositories',
dataType: 'json',