下拉框:


<select id="selectID" >
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
    </select>
 

下面是对下拉框的基本操作:


<script language="javascript">
        $(document).ready(function() {
        //绑定下拉框change事件,当下来框改变时调用 SelectChange()方法
        $("#selectID").change(function() { SelectChange(); }); 
        })
        function SelectChange() {
        //获取下拉框选中项的text属性值
        var selectText = $("#selectID").find("option:selected").text();
        alert(selectText);
        //获取下拉框选中项的value属性值
        var selectValue = $("#selectID").val();
        alert(selectValue);
        //获取下拉框选中项的index属性值
        var selectIndex = $("#selectID").get(0).selectedIndex;
        alert(selectIndex);
        ////获取下拉框最大的index属性值
        var selectMaxIndex = $("#selectID option:last").attr("index");
        alert(selectMaxIndex);
    }     function aa() {
        //设置下拉框index属性为5的选项 选中
        $("#selectID").get(0).selectedIndex = 5;  
    }
    function bb() {
        //设置下拉框value属性为4的选项 选中
        $("#selectID").val(4);
    }
    function cc() {
        //设置下拉框text属性为5的选项 选中
         $("#selectID option[text=5]").attr("selected", "selected");          $("#yyt option:contains('')").attr("selected", true);     }
    function dd() {
        //在下拉框最后添加一个选项
        $("#selectID").append("<option value='7'>7</option>");
    }
    function ee() {
        //在下拉框最前添加一个选项
        $("#selectID").prepend("<option value='0'>0</option>")
    }
    function ff() {
        //移除下拉框最后一个选项
        $("#selectID option:last").remove();
    }     function gg() {
        //移除下拉框 index属性为1的选项
        $("#selectID option[index=1]").remove();
    }     function hh() {
        //移除下拉框 value属性为4的选项
        $("#selectID option[value=4]").remove();
    }
    function ii() {
        //移除下拉框 text属性为5的选项
        $("#selectID option[text=5]").remove();
    }    
    </script>

JQuery 对 Select option 的操作的更多相关文章

  1. JQuery 对 Select option 的操作---转载

    <select id="selectID" > <option value="1">1</option> <optio ...

  2. 转载---JQuery 对 Select option 的操作

    下拉框: <select id="selectID" >         <option value="1">1</option& ...

  3. (网页)JQuery 对 Select option 的操作(转)

    转自博客园: <select id="selectID" > <option value="1">1</option> &l ...

  4. Jquery获取select option动态添加自定义属性值失效

    Jquery获取select option动态添加自定义属性值失效 2014/12/31 11:49:19 中国学网转载 编辑:李强 http://www.xue163.com/588880/3909 ...

  5. jquery获得select option的值和对select option的操作

    <body> <select name="month" id="selMonth" onchange="set()"> ...

  6. jquery获得select option的值 和对select option的操作

    jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...});   //为Se ...

  7. jquery获得select option的值 和对select option的操作【转藏】

    获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); ...

  8. jquery 对select option 增删改查

    一.查 jQuery获取select的Text和Value: 代码如下: 1.当select添加选择事件,当选择其中一项时触发:          $("#select_id"). ...

  9. JS & JQuery 动态处理select option

    原文 出处http://www.51xuediannao.com/html+css/htmlcssjq/cssbuhuanhang.html 今天你问了我一个关于在<select>里动态添 ...

随机推荐

  1. xml问题报错处理

    添加个classPath:/  保存下就能解决报错了  /后面要加个空格,最后一行尖括号里面不能有空格.

  2. 一段处理百分数的js代码

    function percent(s, e, i){ s = Number(s), isNaN(s) && (s = "0"); var n = "%&q ...

  3. Android 网络框架 volley源码剖析

    转载请注明出处:  http://blog.csdn.net/guolin_blog/article/details/17656437 经过前三篇文章的学习,Volley的用法我们已经掌握的差不多了, ...

  4. POJ 1113:Wall

    原文链接:https://www.dreamwings.cn/poj1113/2832.html Wall Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  5. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

  6. Java 菜鸟学习之 script脚本语句

    脚本语句  一般分为  顺序语句   分支语句   循环语句 顺序语句  就是从上到下依次读取 分支语句 是if语句 if(判断条件) { 满足条件执行的语句 } else { 不满足条件执行的语句 ...

  7. 利用angular与后台的交互

    记录的世界是强大的,不管天南海北还是五湖四海,如果利用angular js与后台的交互.angular js 在api上称为是http服务: 下面咱给一个简单的代码看看:简单的利用后台与前端的tab切 ...

  8. js加密的密文让PHP解密(AES算法)

      JS加密代码如下     <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/aes ...

  9. zoj 3673 1729

    1729 Time Limit: 3 Seconds      Memory Limit: 65536 KB 1729 is the natural number following 1728 and ...

  10. HierarchyViewer for iOS 2.0 BETA Introduction

    We know HierarchyViewer is an useful tool in Android SDK. The developer and tester, who haven't the ...