---
title: "jquery chosen插件使用"
author: "chenchi1985"
date: "2012-12-07T10:16:32Z"
tags: []
categories: ["Web前端"]
slug: "jquery-chosen"
draft: false
lastmod: "2012-12-07T10:16:32Z"
id: 1743472
url: "https://chenchi1985.iteye.com/blog/1743472"
---

插件地址：[https://github.com/harvesthq/chosen/](https://github.com/harvesthq/chosen/)

 

使用时，需要先引入jquery，然后再引入chose的js和css

```
<script type="text/javascript" src="@{'/public/js/chosen/chose.jquery.js'}"></script>
<link rel='stylesheet' href='@{'/public/js/chosen/chosen.css'}' type='text/css' media='all'/>
```

 

在select的class属性添加chzn-select，定义select的width属性

 &lt;select style="width: 300px" class="chzn-select" id="obj\_branch\_id" name="obj.branch.id"&gt;

```
    <option value="">选择网点&nbsp;</option>
</select>
```

 

然后在select元素上启用chose

```
jQuery("#obj_branch_id").chosen();
```

 

如果select中的选项发生变化，例如通过ajax更新了option，可以在ajax的回调函数中更新chose

```
jQuery("#obj_branch_id").trigger("liszt:updated");
```