zoukankan      html  css  js  c++  java
  • Select的动态取值(Text,value),添加,删除。兼容IE,FireFox

    <script language="javascript">
    function addSel(o,o1,o2)
    {
        o.options.add(new Option(o2.value,o1.value));
    }
    function delSel(o)
    {
        o.options.remove(o.selectedIndex);
        o.selectIndex=0;
    }
    function getValue(o)
    {
        alert("Text :"+o.options[o.selectedIndex].text+"\nValue:"+o.value);
    }
    </script>
    <select id="sel">
    <option value="1">11111</option>
    <option value="2">22222</option>
    </select>
    value:<input id="addV" type="text">
    text:<input id="addT" type="text">
    <input type="button" value="添加" onclick="addSel(document.getElementById('sel'),document.getElementById('addV'),document.getElementById('addT'))">
    <input type="button" value="删除" onclick="delSel(document.getElementById('sel'))">

    <input type="button" value="取值" onclick="getValue(document.getElementById('sel'))">
  • 相关阅读:
    switch语句
    switch语句
    if语句三种格式
    dowhile语句
    if语句三种格式
    if语句配对
    ansible
    linux系统中网站服务程序(web服务/httpd服务)
    ansible
    ansible
  • 原文地址:https://www.cnblogs.com/kungfupanda/p/1765272.html
Copyright © 2011-2022 走看看