将UL LI单选框转换为多选框

时间:2015-10-27 20:11:50

标签: javascript jquery

我真的需要这个网站上的专家帮助。我希望能够添加和构建功能,以便我的自定义UL LI单选框能够处理多个用户选择。 这是典型情况,用户按住键盘上的CTRL键并从选择框中选择多个值。 这是一个快速的小提琴:http://jsfiddle.net/c2ezuw24/1/ 这是现有的标记: <!DOCTYPE html> < HTML> < HEAD>     < script src =" jquery.min.js"类型="文本/ JavaScript的">< /脚本>     < style type =" text / css">         body {font-family:Arial,Helvetica,Sans-Serif;字体大小:0.75em;颜色:#000;}         .dropdown dd,。dropdown dt,。dropdown ul {             保证金:0像素;             填充:0像素;         }         .dropdown dd {             位置:相对;         }         .dropdown a,。dropdown a:visited {color:#816c5b;文字修饰:无;概述:无;}         .dropdown a:悬停{color:#000;}         .dropdown dt a:hover,。dropdown dt a:focus {             边界:1px solid rgb(128,128,128);         }         .dropdown dt a {             背景:#e4dfcb url(arrow.png)不重复向右滚动;             显示:块;             填充右:20像素;             边界:1px solid rgb(170,170,170);             宽度:150像素;         }         .dropdown dt a span {             光标:指针;             显示:块;             填充:5像素;         }         .dropdown dd ul {            背景:#e4dfcb无重复滚动0 0;            边界:1px solid rgb(170,170,170);            显示:无;            左:0像素;            填充:5px 0px;            位置:绝对的;            顶:2px的;            宽度:汽车;            最小宽度:170像素;            列表样式:无;        }         .dropdown span.value {display:none;}         .dropdown dd ul li a {padding:5px;显示:块;}         .dropdown dd ul li a:hover {background-color:#d0c9af;}         .dropdown img.flag {border:none;垂直对齐:中部;保证金左:10px的; }         .flagvisibility {display:none;}     < /风格>     < script type =" text / javascript">         $(document).ready(function(){             $(" .dropdown img.flag")。addClass(" flagvisibility");             $("。dropdown dt a")。click(function(){                 $("。dropdown dd ul")。toggle();             });             $("。dropdown dd ul li a")。click(function(){                 var text = $(this).html();                 $("。dropdown dt a span")。html(text);                 $("。dropdown dd ul")。hide();                 $("#results")。html("选择的值是:" + getSelectedValue(" sample"));             });             function getSelectedValue(id){                 return $("#" + id).find(" dt span.value")。html();             }             $(document).bind(' click',function(e){                 var $ clicked = $(e.target);                 if(!$ clicked.parents()。hasClass(" dropdown"))                     $("。dropdown dd ul")。hide();             });             $(" #flashSwitcher")。click(function(){                 $(" .dropdown img.flag")。toggleClass(" flagvisibility");             });         });     < /脚本> < /头> <身体GT;     < dl id ="样本"类="下拉">         < dt>< a href ="#">< span>请选择国家< / span>< / a>< / dt>         &LT峰; dd>             < UL>                 < li>< a href ="#">巴西< img class =" flag" SRC =" br.png" ALT ="" />< span class =" value"> BR< / span>< / a>< / li>                 < li>< a href ="#">法国< img class =" flag" SRC =" fr.png" ALT ="" />< span class =" value"> FR< / span>< / a>< / li>                 < li>< a href ="#">德国< img class =" flag" SRC =" de.png" ALT ="" />< span class =" value"> DE< / span>< / a>< / li>                 < li>< a href ="#"> India< img class =" flag" SRC =" in.png" ALT ="" />< span class =" value"> IN< / span>< / a>< / li>                 < li>< a href ="#">日本< img class =" flag" SRC =" jp.png" ALT ="" />< span class =" value"> JP< / span>< / a>< / li>                 < li>< a href ="#">塞尔维亚< img class =" flag" SRC =" cs.png" ALT ="" />< span class =" value"> CS< / span>< / a>< / li>                 < li>< a href ="#">英国< img class =" flag" SRC =" gb.png" ALT ="" />< span class =" value"> UK< / span>< / a>< / li>                 < li>< a href ="#">美国< img class =" flag" SRC =" us.png" ALT ="" />< span class =" value"> US< / span>< / a>< / li>             < / UL>         < / DD>     < / dl的>     < span id ="结果">< / span> < /体> < / HTML>

1 个答案:

答案 0 :(得分:-1)

使用内置的html功能。 http://jsfiddle.net/2v8foz90/

<select multiple>
  <option value="DEDE">Hello</option>
  <option value="FEFE">bonjour</option>
  <option value="SESE">Ciao</option>
  <option value="AEAE">hallo</option>
</select>