zoukankan      html  css  js  c++  java
  • 利用jquery 控制select 实例代码

    //1.获取选中option值
    $('#selectList').val();
    //2.获取选中option的文本
    $('#selectList :selected').text();
    //3.获取多个选中option值、文本
    var foo = [];
    $(
    '#multiple :selected').each(function(i, selected) {
    foo[i]
    = $(selected).text();
    });
    // to get the selected values, just use .val() - this returns a string or array
    foo = $('#multiple :selected').val();
    //4.使用选项option的条件表达式
    switch ($('#selectList :selected').text()) {
    case 'First Option':
    //do something
    break;
    case 'Something Else':
    // do something else
    break;
    }
    //5.删除某个value=2的option
    $("#selectList option[value='2']").remove();
    //6.从list A 移动option到 list B.
    //
    here we have 2 select lists and 2 buttons. If you click the “add” button,
    //
    we remove the selected option from select1 and add that same option to select2.
    //
    The “remove” button just does things the opposite way around.
    //
    Thanks to jQuery's chaining capabilities, what was once a rather tricky undertaking with JS can now be done in 6 lines of code.
    $().ready(function() {
    $(
    '#add').click(function() {
    return !$('#select1 option:selected').appendTo('#select2');
    });
    $(
    '#remove').click(function() {
    return !$('#select2 option:selected').appendTo('#select1');
    });
    });

  • 相关阅读:
    sql初始化XML操作
    c#字符串操作方法实例
    C#日期格式转换
    asp.net中打印指定控件内容
    NET中验证控件表达式汇总
    js中页面刷新和页面跳转的方法总结
    数据库备份与还原SQL代码
    NIO 基础之 Buffer
    Java堆外内存之突破JVM枷锁
    JAVA NIO:Buffer.mark()的用法
  • 原文地址:https://www.cnblogs.com/anmoon/p/1789275.html
Copyright © 2011-2022 走看看