<html>
<head>
<link href="http://localhost/mytests/js/select2.css" rel="stylesheet"/>
<script src="http://localhost/mytests/js/select2.js">
</script>
<script>
$(document).ready(function()
{
$("#e1").select2();
$("#e1").select2(
{
placeholder: "Select a State",
allowClear: true
});
$("#e2_2").select2(
{
placeholder: "Select a State"
});
});
</script>
</head>
<body>
<select id="e1">
<option value="AL">
Alabama
</option>
<option value="AL">
Alabama
</option>
<option value="AL">
Alabama
</option>
<option value="AL">
Alabama
</option>
<option value="AL">
Alabama
</option>
<option value="WY">
Wyoming
</option>
</select>
</body>
上面的代码用于选择城市,也可以搜索选项。顶部的链接用于添加select2.js和select2.css。目前这不起作用。
答案 0 :(得分:0)
这是你的代码工作jsfiddle。请注意小提琴。 包括jquery:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<link href="http://localhost/mytests/js/select2.css" rel="stylesheet"/>
<script src="http://localhost/mytests/js/select2.js">
$("#e1").select2();
$("#e1").select2(
{
placeholder: "Select a State",
allowClear: true
});
$("#e2_2").select2(
{
placeholder: "Select a State"
});