---
title: "struts+jquery控制select多选，并加上title以显示所有option内容"
author: "yinter"
date: "2013-12-03T12:37:48Z"
tags: []
categories: ["Web前端"]
slug: "struts-jquery-select-title-option"
draft: false
lastmod: "2013-12-03T12:37:48Z"
id: 1984164
url: "https://yinter.iteye.com/blog/1984164"
---

```jquery

$(document).ready(function() {
	    $("#toRight").click(function(){
	        $("#dataForm_pubAddress_source option:selected").each(function(){
                $("#dataForm\\.pubAddress").append("<option value=" + $(this).val() + " title=" + $(this).html() + ">" + $(this).html() + "</option>");
                $(this).remove();
	        });
	    });
	
	    $("#toLeft").click(function(){    
	        $("#dataForm\\.pubAddress option:selected").each(function(){
                $("#dataForm_pubAddress_source").append("<option value=" + $(this).val() + " title=" + $(this).html() + ">" + $(this).html() + "</option>");//这个方法是默认在后面添加
                $(this).remove();
	        });
	    });
	    
	    $('option','#dataForm_pubAddress_source').attr('title',function(){ 
   			return this.innerHTML; 
		});
		$('option','#dataForm\\.pubAddress').attr('title',function(){ 
   			return this.innerHTML; 
		});
	});

```



```struts

<tr>
					<td style="width: 200px;" id="dataForm.pubAddress.label">
						地址：<font color="#ff0000">*</font>
					</td>
					<td>
						<table>
							<tr>
								<td>
									<s:select size='8' multiple="true" 
									id="dataForm_pubAddress_source" cssStyle="width: 360px;height:60px" name="dataForm.pubAddress_source" 
									list="mpOfficeLocationList" headerKey="" listKey="code" listValue="parmValue">
									</s:select>
								</td>
								<td>
									<input type="button" value=" >> " id="toRight" />
									<br />
									<br />
									<input type="button" value=" << " id="toLeft" />
								</td>
								<td>
									<!-- 
									<select size='10' multiple="multiple" 
									id="dataForm.pubAddress" name="dataForm.pubAddress" style="width: 300px;height:60px">
									</select>
									 -->
									<s:select size='8' multiple="true" 
									id="dataForm.pubAddress" cssStyle="width: 360px;height:60px" name="dataForm.pubAddress" 
									list="mpOfficeLocationSelectList" headerKey="" listKey="code" listValue="parmValue">
									</s:select>
								</td>
							</tr>
						</table>
					</td>					
				</tr>

```



```java

action中定义变量：
	/** 可选地址 */
	private List<PbmParamValue> mpOfficeLocationList;
	/** 已选地址 */
	private List<PbmParamValue> mpOfficeLocationSelectList;

```