.net 初学者。学习笔记 [html的<select>下拉标签option赋值]

前台:

<td>
    <asp:HiddenField ID="hidVehTypeId" runat="server" />
    <asp:HiddenField ID="hidVehTypeName" runat="server" />
    <select id="vehType1" name="vehType1">
     </select>
</td>

后台(此方法须在页面加载是调用):

        /// <summary>
        /// 查询并把值赋予隐藏域
        /// </summary>
        public void SelectVehType()
        {
            IList<RJ.Model.data_dictionary> dictionData = Business.UserInfo.SelectVehType();
            string vehTypeId = "";
            string vehTypeName = "";
            foreach (var item in dictionData)
            {
                vehTypeId += "," + item.data_key;
                vehTypeName += "," + item.data_value;
            }

            this.hidVehTypeId.Value = vehTypeId.Substring(1);
            this.hidVehTypeName.Value = vehTypeName.Substring(1);
        }

JS:

    <script type="text/javascript">
        function SelectVehType() {
            var typeid = $("#hidVehTypeId").val();
            var typeidsil = typeid.split(",");
            var typename = $("#hidVehTypeName").val();
            var typenamesil = typename.split(",");

            for (var i = 0; i < typeidsil.length; i++) {
                var sel = document.getElementById('vehType1');
                var opt = document.createElement('option');
                opt.setAttribute('value', typeidsil[i]);
                opt.innerText = typenamesil[i];
                sel.appendChild(opt);

            }
        }
    </script>

转载于:https://www.cnblogs.com/nanmuhigh/archive/2012/08/24/2654408.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值