jquery è·åselectå¤éä¸ææ¡ææé项çå¼å¯ä»¥å¦ä¸å®ç°
var all = "";
$("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>
</select>
<input type="button" value="ç¹å»æ¾ç¤ºéæ©ç项ç®">
ç®å设置ä¸ä¸cssæ ·å¼
select{width:200px;height:150px;padding:10px;border:4px dashed #ccc;}
select option{margin:5px;}
input[type='button']{width:200px;height:35px;margin:10px;border:2px dashed #ebbcbe;}
ç¼åjquery代ç ï¼å®ç°è·åææå¼åè·åéä¸å¼
$(function(){
$("input:button").click(function() {
var all = "";
$("select option").each(function() {
all += $(this).attr("value")+" ";
});
var sel = $("select").val();
alert("å¤éå表ææçvalueå¼:"+all+"ï¼å
¶ä¸è¢«éä¸çæ¯:"+sel+"ã");
});
})
è§å¯ææ