下拉框

<select id="selectID" name="selectName">

<option vlaue="1">1</option>

<option vlaue="2">2</option>

<option vlaue="3">3</option>

</select>

(一)JQuery对select的操作

// 获取select本身属性name的值

console.log($("#selectID").prop("name"));

(二)JQuery对select option的操作

//选择更改事件

$("#selectID").change(function(){   selectChangeFunCode;      });

//获取属性值

//获取下拉框选中项的text属性值
        var selectText = $("#selectID").find("option:selected").text();
        console.log(selectText);
        //获取下拉框选中项的value属性值    ①
        var selectValue = $("#selectID").val();
        console.log(selectValue);
        //获取下拉框选中项的index属性值
        var selectIndex = $("#selectID").get(0).selectedIndex;
        console.log(selectIndex);
        ////获取下拉框最大的index属性值
        var selectMaxIndex = $("#selectID option:last").attr("index");
        console.log(selectMaxIndex);

//获取文本值

//获取下拉框选中项的  文本内容     ②

var selectHtml = $("#selectID").find("option:selected").html();
      console.log(selectHtml );

要更改 下拉框其中一个option,需要同时操作①②

       //设置下拉框index属性为5的选项 选中
        $("#selectID").get(0).selectedIndex = 5;  
  
        //设置下拉框value属性为4的选项 选中
        $("#selectID").val(4);

//设置下拉框text属性为5的选项 选中
         $("#selectID option[text=5]").attr("selected", "selected");

         $("#yyt option:contains('')").attr("selected", true);
        //在下拉框最后添加一个选项
        $("#selectID").append("<option value='7'>7</option>");
  
        //在下拉框最前添加一个选项
        $("#selectID").prepend("<option value='0'>0</option>")

//移除下拉框最后一个选项
        $("#selectID option:last").remove();

//移除下拉框 index属性为1的选项
        $("#selectID option[index=1]").remove();
   
        //移除下拉框 value属性为4的选项
        $("#selectID option[value=4]").remove();

//移除下拉框 text属性为5的选项
        $("#selectID option[text=5]").remove();

【jq】JQuery对select的操作的更多相关文章

  1. Jquery对select的操作(附日历天数变化代码)

    转载请注明出处. 逃不开传统的四种操作:增.删.改.查. <四处搜刮了jquery对select操作的代码,汇集一下,方便以后查看.日历天数变化代码为原创.> [增]: $("# ...

  2. jQuery关于Select的操作

    jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...

  3. jQuery的select相关操作

    例: <select class="selector" id="selector"></select> 1.设置value为pxx的项选 ...

  4. jQuery select的操作代码

    jQuery對select的操作的实际应用代码. //改變時的事件  复制代码代码如下: $("#testSelect").change(function(){ //事件發生  j ...

  5. jQuery对Select操作大集合

    介绍了jQuery对Select的操作进行了详细的汇总. 1.jQuery添加/删除Select的Option项: 2.$("#select_id").append("& ...

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

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

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

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

  8. jquery select 常用操作总结

    由于在项目各种所需,经常碰到select不种操作的要求,今天特意总结了一下,分享: jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id&q ...

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

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

随机推荐

  1. [NodeJs] 用Nodejs+Express搭建web,nodejs路由和Ajax传数据并返回状态,nodejs+mysql通过ajax获取数据并写入数据库

    小编自学Nodejs,看了好多文章发现都不全,而且好多都是一模一样的 当然了,这只是基础的demo,经供参考,但是相信也会有收获 今天的内容是用Nodejs+Express搭建基本的web,然后呢no ...

  2. JavaScript 常见面试题

    此文内容多为 JavaScript 对数组理解及运用. 1.如何消除一个数组里面重复的元素? var arr = [1, 2, 3, 3, 4, 4, 5, 5, 6, 1]; var newArr ...

  3. maven 安装下载与配置 代理设置 《解决下载慢问题》

    maven:下载地址http://mirror.bit.edu.cn/apache/maven/maven-3/ 解压之后配置环境 %maven_home%  d:\*****path 中添加 %ma ...

  4. 朴素贝叶斯文本分类实现 python cherry分类器

    贝叶斯模型在机器学习以及人工智能中都有出现,cherry分类器使用了朴素贝叶斯模型算法,经过简单的优化,使用1000个训练数据就能得到97.5%的准确率.虽然现在主流的框架都带有朴素贝叶斯模型算法,大 ...

  5. CVE-2018-10945 mongoose越界访问

    Hello , I found a vulneratility in mg_handle_cgi function The function is in mongoose.c , line 8925  ...

  6. 关于Nodejs开发桌面应用。NW.js 和 Electron 优缺点分析对比

    从开发角度来说,选择用 nw.js 还是 election ,区别其实不是很大.大部分工作还是在自己的 javascript 和 HTML 上.国内比较有名的,比如微信web开发工具.钉钉都是基于 n ...

  7. Linux的Transparent Hugepage与关闭方法

    Transparent HugePages是在运行时动态分配内存的,而标准的HugePages是在系统启动时预先分配内存,并在系统运行时不再改变. 因为Transparent HugePages是在运 ...

  8. spider-抓取网页内容(Beautiful soup)

    http://jingyan.baidu.com/article/afd8f4de6197c834e386e96b.html http://cuiqingcai.com/1319.html Windo ...

  9. PHPredis安装

    一.PHPredis下载链接:https://pan.baidu.com/s/1bz0EaJgDpp2ADQJCJOHJGA 二.解压并进入目录 三.发现没有configure文件,需要安装autoc ...

  10. Git修改子模块的路径

    Git在两个地方存储有关子模块的信息.第一个是在一个名为的文件中.gitmodules,该文件被签入git存储库.对此文件的更改将传播到其他存储库. 另一个位置在.git/config,并且它是执行大 ...