码迷,mamicode.com
首页 > 其他好文 > 详细

输出选中的下拉框的值

时间:2017-03-22 16:06:02      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:images   code   selected   color   ntb   ted   选择   选中   val   

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
        <select id="objsel" name="objsel" size=8 multiple>
            <option value="0" selected>请选择
            <option value="1">测试一
            <option value="2">测试二
            <option value="3">测试三
            <option value="4">测试四
            <option value="5">测试五
        </select>
        <input type="button" onclick="checkselect();" value="输出">
        选中的项目:<input type="text" id="output" name="output">
</body>
</html>
<script language="JavaScript">
    function checkselect(){
        var x = document.getElementById("objsel");
        var t = document.getElementById("output");
        var count=0;
        var intvalue="";
        for(i=0;i<x.length;i++){
            if(x.options[i].selected){
                intvalue+=x.options[i].value+",";
                count++;
            }
        }
        t.value=intvalue.substr(0,intvalue.length-1);
//        alert(count);
    }
</script>

效果图:

技术分享

输出选中的下拉框的值

标签:images   code   selected   color   ntb   ted   选择   选中   val   

原文地址:http://www.cnblogs.com/heyiming/p/6600329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!