跳到主文
部落格全站分類:數位生活
html做listbox單選
html
<select id="test1" multiple="true"> //設multiple為true <option id='test1_opt1'>1</option> <option id='test1_opt2'>2</option> <option id='test1_opt3'>3</option> <option id='test1_opt4'>4</option> ... </select>
jquery
var lastSelectedID=-1; $("select#test1").change(function(){ var tmpLastSelectedID=-1; jQuery('option:selected', this).each(function(){ //避開滑鼠直接選2個以上 if(tmpLastSelectedID>0){ $(this).attr("selected",false); return true; } //避開ctrl點選 if (lastSelectedID==$(this).attr("id")){ $(this).attr("selected",false); return true; }else{ tmpLastSelectedID=$(this).attr("id"); } }); lastSelectedID=tmpLastSelectedID; });
原始網址:http://kevyu.blogspot.com/2009/09/htmllistbox.html
白羽‧獨舞
carllee413 發表在 痞客邦 留言(0) 人氣()
留言列表