1.判断select选项中 是否存在Value="value"的option元素

function jsSelectIsExitItem(objSelect,objItemValue)
{ var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
isExit = true;
break;
}  
}
return isExit;
}

2.向select选项中 加入一个Item

function addOptions(objsel,text,value){

if (valueExit(objsel,value)) {
alert("改属性值已经存在");
};
var option = new Option(text,value);
objsel.add(option,null);
alert('添加成功');

}

3.从select选项中 删除一个Item

function removeOpt(objSelect,objItemValue)
{
//判断是否存在
if(valueExit(objSelect,objItemValue))
{
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
objSelect.options.remove(i);
break;
}

}

alert("成功删除");

}
else
{
alert("该select中 不存在该项");
}

}

4.修改select选项中 value="paraValue"的text为"paraText"

<script type="text/javascript">
var select = document.getElementById('sele');
function chaTeByval(objSelect,objItemText,objItemValue)
{
//判断是否存在
if(isExit(objSelect,objItemValue))
{
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
objSelect.options[i].text = objItemText;
break;
}
}
alert("成功修改"); }
else
{
alert("该select中 不存在该项");
}
} chaTeByval(select,'美国',6);

5.设置select中text="paraText"的第一个Item为选中

<script type="text/javascript">
var select = document.getElementById('sele');
function selbyText(objSelect,objItemText)
{
//判断是否存在
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].text == objItemText)
{
objSelect.options[i].selected = true;
isExit = true;
break;
}
}
if(isExit)
{
alert("成功选中"); }
else
{
alert("该select中 不存在该项");
}
} selbyText(select,'上海');
</script>

6.设置select中value="paraValue"的Item为选中

<script type="text/javascript">
var select = document.getElementById('sele');
function selbyText(objSelect,objItemValue)
{
//判断是否存在
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == objItemValue)
{
objSelect.options[i].selected = true;
isExit = true;
break;
}
}
if(isExit)
{
alert("成功选中"); }
else
{
alert("该select中 不存在该项");
}
} selbyText(select,1);
</script>

7.得到select的当前选中项的value       select.options[select.options.selectedIndex].value

8.得到select的当前选中项的text      select.options[select.options.selectedIndex].text

9.得到select的当前选中项的Index    select.options.selectedIndex;

10.清空select的项           select.options.length=0   select.innerHTML="";

 

最新文章

  1. 玩转UICollectionViewLayout
  2. .Net Core下如何管理配置文件
  3. 渲染物体到一张UITexture上
  4. 零件分组_DP
  5. Fatal error: Call to a member function bind_param() on a non-object in
  6. 【CSLA】Component-based,Scalable,LogicalArchitecture
  7. 使用django+mysql+scrapy制作的一个小说网站
  8. org/hamcrest/SelfDescribing
  9. Train Problem II(卡特兰数+大数乘除)
  10. 读改善c#代码157个建议:建议7~9
  11. Java基础学习
  12. 【Android Developers Training】 17. 停止和重启一个Activity
  13. lesson - 3 ls /cd /path /alias /快捷键
  14. Saltstack的安装和配置
  15. JSP常见的三个编译指令
  16. linux /proc/sys/vm/中各个文件含义
  17. python学习笔记3-列表
  18. VirtualBox导致Vmware的虚拟机桥接模式网络不通
  19. 开发一个简单的postgresql extension
  20. VCL界面控件DevExpress VCL发布v18.2.2|附下载

热门文章

  1. Remove Duplicates from Sorted Array II ——LeetCode
  2. Break、continue、return用法(C++)
  3. CLOSE-UP FORMALWEAR_意大利进口_2015秋冬_男装发布会_西装图片系列_男装西装设计资料_WeArTrends时尚资讯网_国内最专业的服装设计资讯网站
  4. python BDD&amp;TDD
  5. mysql group by的用法 注意
  6. 漫步支持向量机(svm)之一
  7. ios 打电话结束返回到应用中
  8. sparkSQL1.1入门之二:sparkSQL执行架构
  9. IOS Dictionary和Model相互转换
  10. Ubuntu设置环境变量的几种方法