jquery 移动select元素

方法一:

function move(dir) { // 移动商品显示顺序 var obj = $("#goodsIds"); if (obj.attr("length") <= 1) { return; } var sel = obj.find("option:selected"); if (isEmpty(sel.val())) { top.Dialog.alert("请选择需要移动的商品!"); return; } if (dir == "first" || dir == "last") { // 置顶或置底 var val = sel.val(); var option = "<option value='" + val + "'>" + sel.text() + "</option>"; if (dir == "first") { obj.prepend(option); } else { obj.append(option); } sel.remove(); obj.val(val).attr("class", "ipt"); } else { // 向前移或向后移 var target = null; if (dir == "prev") { target = sel.prev(); } else { target = sel.next(); } if (typeof(target.val()) != "undefined") { var val1 = sel.val(); var text1 = sel.text(); var val2 = target.val(); var text2 = target.text(); sel.val(val2).text(text2); target.val(val1).text(text1); obj.val(val1).attr("class", "ipt"); } } } 

 

方法二:

function move(id, dir) { var obj = $("#" + id); var sel = obj.find("option:selected"); if (sel.length == 0) { return; } switch(dir) { case "first": obj.prepend(sel); break; case "prev": sel.insertBefore(sel.prev()); break; case "next": sel.insertAfter(sel.next()); break; case "last": obj.append(sel); break; } obj.attr("class", "image-sel"); } 

样式:

.image-sel{width:150px}

你可能感兴趣的:(jquery,function,Class)