zoukankan      html  css  js  c++  java
  • 使用jQuery实现option的上移和下移

    基本思路:
        上移:(1)获取当前选中的元素的索引值
                (2)判断当前元素是否为第一个元素
                (3)如果是,则不执行上移操作,如果不是,则则调用insertBefore方法插入到他的prev(紧邻的上一个)元素之前
    1 var up = function () {
    2          var selectedIndex = $("#SelectedAddressIds option:selected").index(); //获取当前选中元素的索引
    3          if(selectedIndex >= 1){
    4                   // 插入上一个
    5                $("#SelectedAddressIds option:selected").insertBefore($("#SelectedAddressIds option:selected").prev('option'));
    6          }
    7 }
      下移:(1)获取所有option元素的索引值
                  (2)获取当前选中元素的索引值
                  (3)判断当前选中元素是否为最后一个元素,如果是,则不执行下移,如果不是则调用insertAfter方法插入到他的next(紧邻的下一个)元素的后面。
     1 var down = function () {
     2             // 获取最后一个option的索引值
     3             var optionNum = $("#SelectedAddressIds option").size() - 1;
     4             // 获取当前选中元素的索引值
     5             var selectedIndex = $("#SelectedAddressIds option:selected").index();
     6 
     7             if(selectedIndex < 6){
     8                 // 插入下一个
     9                 $("#SelectedAddressIds option:selected").insertAfter($("#SelectedAddressIds option:selected").next('option'));
    10             }
    11 }
  • 相关阅读:
    linux fork函数与vfork函数,exit,_exit区别
    wait、waitpid 僵尸进程 孤儿进程
    storage size of ‘oldact’ isn’t known
    xpath选择器使用
    linux read和write函数
    Sql case when用法
    linux select
    sublime使用
    notepad++使用技巧及插件汇总
    jQuery Ajax 实例 具体介绍$.ajax、$.post、$.get的使用
  • 原文地址:https://www.cnblogs.com/enjoymylift/p/5974789.html
Copyright © 2011-2022 走看看