当前位置:编程学习 > C#/ASP.NET >>

jquery实现,下拉框选几,就出现几个checkbox。

下拉框是1-20的数字。 选择下拉框的数字后,则出现几个数目的checkbox值 下拉框选几,就出现几个checkbox。 --------------------编程问答-------------------- 1、动态创建【主要是控制位置】
2、先创建好,用隐藏和显示来控制【位置不是问题】
推介第一种。 --------------------编程问答-------------------- 这类简单问题,建议你还是找一个比较完整的程序开发教程看看。

--------------------编程问答--------------------
<html>
<head>
    <title></title>
    <script src="jquery-1.4.2.js"></script>
    <script type="text/ecmascript">
        $(function () {
            $("#selectnum").change(function () {
                $(this).each(function () {
                    var count = parseInt($(this).val());
                    for (var i = 0; i < count; i++) {
                        if (i % 5 == 0) { $("#result").append("<br/>") }
                        $("#result").append("<input type='checkbox' id=checkbox" + i + " value=checkbox" + i + ">checkbox" + i + "</input>");
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <select id="selectnum">
                <option id="num1">10</option>
                <option id="num2">20</option>
                <option id="num3">30</option>
            </select>
        </div>
        <div id="result">
        </div>
    </form>
</body>
</html>
--------------------编程问答--------------------

<select id="selectnum"></select>
<div id="result"></div>

<script>
$(Array(20)).each(function (i) {
$('#selectnum').append('<option>' + (i + 1) + '</option>');
    });
$('#selectnum').change(function () {
$('#result').empty();
$(Array(Number($(this).val()))).each(function (i) {
$('#result').append("<input type='checkbox' /> checkbox" + (i + 1) + "<br>");
});
    });
</script>
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,