日期:2014-05-16 浏览次数:21052 次
<select id="multiple" multiple="multiple" name="multiple">
<option value='1'>Multiple</option>
<option value='2'>Multiple2</option>
<option value='3'>Multiple3</option>
<option value='4'>Multiple4</option>
</select>
赋值后的结果
<select id="multiple" multiple="multiple" name="multiple">
<option value='1' selected="selected">Multiple</option>
<option value='2'>Multiple2</option>
<option value='3' selected="selected">Multiple3</option>
<option value='4'>Multiple4</option>
</select>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
</head>
<body>
<select id="multiple" multiple="multiple" name="multiple" data="1,3">
<option value='1'>Multiple</option>
<option value='2'>Multiple2</option>
<option value='3'>Multiple3</option>
<option value='4'>Multiple4</option>
</select>
<script type="text/javascript">
jQuery(function($){
var a=$('#multiple').attr('data');
$('#multiple option').each(function() {
if(a.indexOf($(this).val())!= -1){
$(this).attr('selected',true);
}
});