`
橄榄绿
  • 浏览: 272754 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

select options remove的问题 js

阅读更多

options remove的问题

 

很多朋友习惯用oSelect.options[n].remove()这样的方法来删除下拉框内的选项,而且这样在IE里也能很好的使用,但是很不幸的是这个不是标准方法,是微软的IE实现的一个方法,在firefox等其他浏览器里就不能被支持。标准的方法是把oSelect.options.length值改变来删除options,但是这样的话就不好灵活的删除某一个option了,不过还是有变通的办法,就在删除前把要删除的option移动到最后一个,然后把整体的options.length --,就达到目的了,讲到这个偶有想起了数据结构那门课。

对了,补充一点,options.add方法也不是标准方法,所以添加option用oSelect.options[oSelect.length] = option;这样的方法来添加才是跨浏览器的方法。

分享到:
评论

相关推荐

    javascript Select标记中options操作方法集合

    javascript操作Select标记中options集合 先来看看options集合的这几个方法: options.add(option)方法向集合里添加一项option对象; options.remove(index)方法移除options集合中的指定项; options(index)或options...

    JS、jQuery中select的用法详解

    1.js var obj=document.getElementById(selectid); obj.options.length = 0; //清除所有内容 obj.options[index] = new Option("three",3);...obj.options.remove(index);//删除选中项 2.jquery $("#se

    JS动态添加与删除select中的Option对象(示例代码)

     } //动态删除select中的某一项option: function delOneOption(index){ document.getElementById(“user_dm”).options.remove(index); } // 动态添加select中的项option: function addOneO

    使用js对select动态添加和删除OPTION示例代码

    <select id=”... 动态删除select中的某一项option: document.getElementById(“ddlResourceType”).options.remove(indx); 动态添加select中的项option: document.getElementById(“ddlResourceType”

    js的日历时间控件

    if(this.options.timePicker&&this.options.datePicker){this.options.currentFormat=this.options.dateTimeFormat}else{if(this.options.timePicker){this.options.currentFormat=this.options.timeFormat}else{...

    可用 js ajax代码

    typeSelect.options.remove(j); } var content8 = xmlHttp.responseText; eval(content8); }else { alert("请求失败,错误码=" + xmlHttp.status); } } } public Object reg...

    JavaScript权威指南

    JavaScript权威指南 犀牛书 Chapter 1. Introduction to JavaScript Section 1.1. JavaScript Myths Section 1.2. Versions of JavaScript Section 1.3. Client-Side JavaScript Section 1.4. JavaScript ...

    图形jquery.gvChart-1.0.1.min.js

    copy.find("select").each(function () { var $field = $(this); $field.find(":selected").attr("selected", "selected"); }); copy.find("textarea").each(function () { // Fix for ...

    jquery需要的所有js文件

    h&&d(h)}return(/input|select|textarea|button|object/.test(e)?!b.disabled:"a"==e?b.href||c:c)&&d(b)}a.ui=a.ui||{};a.ui.version||(a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20...

    jQuery实现在下拉列表选择时获取json数据的方法

    本文实例讲述了jQuery实现在下拉列表选择时获取json数据的方法。分享给大家供大家参考。... var options = select.attr('options'); $('option', select).remove(); $.each(data, function(index, array) { o

    JavaScript笔记

    JavaScript:定义行为和动作 (基于对象和事件驱动的客户端脚本语言;也是一种广泛应用于客户端Web开发的脚本语言) 基于对象:网页中的一切元素都是假象!不需要new,即可直接使用 事件驱动:JavaScript的执行都是...

    db:轻松访问mongodb,redis或ds

    D B 版权所有2020 Sleepless Software Inc.保留所有权利 关于 一个实用的通用界面,用于与大多数通用数据库进行对话。 支持: AWS DynamoDB Google FireBase ...remove( criteria, callback( num_rem

    DecoratedStockChart:更好的Highstock,丰富了基于Bootstrap的控件

    装饰图 更好的Highstock,丰富了基于Bootstrap的控件 ... on-attribute-select =" onAttributeSelect(attr, security, options) " on-security-remove =" onSecurityRemove(id) " highstock-options

    UE(官方下载)

    The selected text compare allows you to select portions of text between 2 files and execute a compare on ONLY the se Using the SSH/telnet console A tutorial for UltraEdit/UEStudio's SSH/telent ...

    asp连接数据库代码实例

    转到:<select name=\"select\" onChange=\'javascript:window.open(this.options[this.selectedIndex].value,\"_top\")\'> <%for p=1 to rs.pagecount%> <option value=\"?page=<%=p%>\" ...

    计算机应用技术(实用手册)

    解决方法:打开机箱,把主板上的一节纽扣电池取出,换上一节新的既可,或是CMOS被放电了,从新进入CMOS设置时间保存并退出就可解决此问题。 Press F1 tocontinue ,DEL to enter SETUP 按F1可以继续启动,按DEL进入...

    php.ini-development

    Language Options ; ;;;;;;;;;;;;;;;;;;;; ; Enable the PHP scripting language engine under Apache. ; http://php.net/engine engine = On ; This directive determines whether or not ...

Global site tag (gtag.js) - Google Analytics