zoukankan      html  css  js  c++  java
  • JS技巧:JS对select动态添加options操作[IE&FireFox兼容]

    <select id="ddlResourceType" onchange="getvalue(this)">
    </select>

        动态删除select中的所有options: 
           document.getElementById("ddlResourceType").options.length=0; 

         动态删除select中的某一项option: 
           document.getElementById("ddlResourceType").options.remove(indx);  

         动态添加select中的项option: 
           document.getElementById("ddlResourceType").options.add(new Option(text,value)); 

         上面在IE和FireFox都能测试成功,希望以后你可以用上。 
    其实用标准的DOM操作也可以,就是document.createElement,appendChild,removeChild之类的。 

    取值方面
        function getvalue(obj)
         ...{
             var m=obj.options[obj.selectedIndex].value
             alert(m);//获取value
             var n=obj.options[obj.selectedIndex].text
             alert(n);//获取文本
         }

  • 相关阅读:
    第三章 系统总线
    人工神经网络及其应用
    专家系统
    遗传算法
    搜索算法策略
    js判断有无属性及新添属性
    vue 文件插件 Vetur 设置说明官网
    vue 获得当前无素并做相应处理
    VUE style 绑定
    vue入门基础知识点测试
  • 原文地址:https://www.cnblogs.com/luhaiyan/p/2046621.html
Copyright © 2011-2022 走看看