$("select option").each(function() {
all += $(this).attr("value")+" "
})
而值获取被选中的值可用如下代码实现
$("select").val()
下面给出实例代码:
创建Html元素:一个多选列表和一个按钮
<select id="multi-sel" multiple="multiple">
<option value="1">萝卜,我的value是1</option>
<option value="2">青菜,我的value是2</option>
<option value="3">小葱,我的value是3</option>
<option value="4">豆腐,我的value是4</option>
下面是我做的一个范例,你可以参考一下<!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/htmlcharset=utf-8" />
<title>自定义表单1 - powered by dedecms</title>
<link href="img/nspage.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="../include/dedeajax2.js"></script>
</head>
<body>
<div class="main mceneter">
<div class="toplogo">
<div class="logo">
<a href="/"><img src="/templets/default/images/logo.gif" /></a>
</div>
<div class="title">
<a href='diy.php?action=list&diyid=1'>自定义表单1</a> >发布信息
</div>
</div>
<div class="cmain">
<div class="ctitle">
<h1>自定义表单1发布</h1>
<span></span>
</div>
<div class="cbox mceneter">
<div class="maplist">
<br />
<form action="/plus/diy.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="action" value="post" />
<input type="hidden" name="diyid" value="1" />
<input type="hidden" name="do" value="2" />
<table style="width:97%" cellpadding="0" cellspacing="1">
<tr>
<td align="right" valign="top">范例:</td>
<td><select name='fl' style='width:150px'><option value='男'>男</option>
<option value='女'>女</option>
<option value='人妖'>人妖</option>
</select>
</td>
</tr>
<input type="hidden" name="dede_fields" value="fl,select" />
<input type="hidden" name="dede_fieldshash" value="db5f139909450665fd4b641fff161416" /></table>
<div align='center' style='height:30pxpadding-top:10px'>
<input type="submit" name="submit" value="提 交" class='coolbg' />
<input type="reset" name="reset" value="重 置" class='coolbg' />
</div>
</form>
</div>
</div>
</div>
</div>
<div class="copyright mceneter">
Powered by <a href="http://www.dedecms.com" target="_blank">DedeCMS</a>© 2004-2009 <a href="http://www.desdev.cn" target="_blank">DesDev</a>Inc.
</div>
</body>
</html>
var arr = [1,2,3,4,5,6,7,8,9,10]var result = new Array(3)
for(var i = 0 i < result.length i++){
result[i] = arr.splice(Math.random()*arr.length>>>0, 1)[0]
}
console.info(result)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)