zoukankan      html  css  js  c++  java
  • .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>
    分享到: 更多
  • 相关阅读:
    微信消息类型和事件类型
    lnmp环境搭建脚本
    laravel框架踩过的坑
    vue结构详解
    PHP消息队列实现及应用
    laravel 运行错误
    笔记分享
    cf730e
    cf 730i
    cf 731f
  • 原文地址:https://www.cnblogs.com/nanmuhigh/p/2654408.html
Copyright © 2011-2022 走看看