网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 js操作select下拉框
范文
    1.判断select选项中 是否存在value=paravalue地item
    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 jsadditemtoselect(objselect, objitemtext, objitemvalue) {
    //判断是否存在
    if (jsselectisexititem(objselect, objitemvalue)) {
    alert(该item地value值已经存在);
    } else {
    var varitem = new option(objitemtext, objitemvalue);
    objselect.options.add(varitem);
    alert(成功加入);
    }
    }
    // 3.从select选项中 删除一个item
    function jsremoveitemfromselect(objselect, objitemvalue) {
    //判断是否存在
    if (jsselectisexititem(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中选中地项
    function jsremoveselecteditemfromselect(objselect) {
    var length = objselect.options.length - 1;
    for(var i = length; i >= 0; i--){
    if(objselect[i].selected == true){
    objselect.options[i] = null;
    }
    }
    }
    // 5.修改select选项中 value=paravalue地text为paratext
    function jsupdateitemtoselect(objselect, objitemtext, objitemvalue) {
    //判断是否存在
    if (jsselectisexititem(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中 不存在该项);
    }
    }
    // 6.设置select中text=paratext地第一个item为选中
    function jsselectitembyvalue(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;
    }
    }
    //show出结果
    if (isexit) {
    alert(成功选中);
    } else {
    alert(该select中 不存在该项);
    }
    }
    // 7.设置select中value=paravalue地item为选中
    document.all.objselect.value = objitemvalue;
    // 8.的到select地当前选中项地value
    var currselectvalue = document.all.objselect.value;
    // 9.的到select地当前选中项地text
    var currselecttext = document.all.objselect.options[document.all.objselect.selectedindex].text;
    // 10.的到select地当前选中项地index
    var currselectindex = document.all.objselect.selectedindex;
    // 11.清空select地项
    document.all.objselect.options.length = 0;
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/15 16:01:56