jQuery下拉框操作系列$("option:selected",this) &&(锋利的jQuery)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ???<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ???<title>下拉框应用</title> ???<script src="../../js/jquery-1.4.4.min.js"></script></head><body> ???<div class="centent"> ???????<select multiple id="select1" style="width:100px; height:160px;"> ???????????<option value="1">选项1</option> ???????????<option value="2">选项2</option> ???????????<option value="3">选项3</option> ???????????<option value="4">选项4</option> ???????????<option value="5">选项5</option> ???????????<option value="6">选项6</option> ???????????<option value="7">选项7</option> ???????????<option value="8">选项8</option> ???????</select> ???????<div> ???????????<span id="add">选中添加到右边≥≥</span> ???????????<span id="add_all">全部添加到右边≥≥</span> ???????</div> ???</div> ???<div class="centent"> ???????<select multiple id="select2" style="width:100px; height:160px;"></select> ???????<div> ???????????<span id="remove">选中删除到左边<<</span> ???????????<span id="remove_all">全部删除到左边<<</span> ???????</div> ???</div> ???<script> ???????$(function () { ???????????$("#add").click(function () { ???????????????var $options = $("#select1 option:selected"); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select2"); ??//追加到select2 ???????????}) ???????????$("#add_all").click(function () { ???????????????var $options = $("#select1 option"); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select2"); ??//追加到select2 ???????????}) ???????????$("#select1").dblclick(function () { ???????????????var $options = $("option:selected", this); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select2"); ??//追加到select2 ???????????}) ???????????$("#remove").click(function () { ???????????????var $options = $("#select2 option:selected"); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select1"); ??//追加到select2 ???????????}) ???????????$("#remove_all").click(function () { ???????????????var $options = $("#select2 option"); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select1"); ??//追加到select2 ???????????}) ???????????$("#select2").dblclick(function () { ???????????????var $options = $("option:selected", this); ?//获取选中的选项 ???????????????//var $remove = $options.remove(); ?//删除下拉列表中选中的选项 ???????????????$options.appendTo("#select1"); ??//追加到select2 ???????????}) ???????}) ???</script></body></html>
jQuery下拉框操作系列$("option:selected",this) ?&&(锋利的jQuery)
原文地址:https://www.cnblogs.com/chaonuanxi/p/10336297.html