bootstrap 下拉选择框select实现从服务器加载option

昨天做了一个下拉菜单中的item从服务器加载,发现用在项目中并不合适,改用下拉选择框

前台代码:

<span style="font-family:Times New Roman;font-size:18px;">            <div class="form-group">
                <label class="col-md-2 control-label" for="unitpart">设备分中心</label>
                <div class="col-md-10">
                    <select class="form-control" id="unitItem"></select>
                </div>                
            </div></span>
<span style="font-family:Times New Roman;font-size:18px;"><span style="white-space:pre">	</span>var unitItem = $("#unitItem").val();//取出传到后台的option的value值</span>
<span style="font-family:Times New Roman;font-size:18px;">            $("#unitItem").bind("click", function () {
                $.ajax({
                    url: "/control/showunit/",
                    dataType: "json",
                    success: function (data) {
                        $.each(data, function (index, units) {
                            $("#unitItem").append("<option value="+units.id+">" + units.unit + "</option>");
                        });
                    },

                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("error");
                    }
                });
            });</span>
另外注意一点,在取radio单选框中的值和文本值时的代码:

<span style="font-family:Times New Roman;font-size:18px;"> <div class="form-group">
                <label class="col-md-2 control-label">设备摄像头类型</label>
                <div class="col-md-10" id="camera_type">
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="01" />xx1
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="02" />xx2
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="03" />xx3
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="04" />xx4
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="05" />xx5
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="06" />xx6
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="07" />xx7
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="08" />xx8
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="09" />xx9
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="camera_type1" value="10" />xx10
                    </label>
                </div>
            </div>         </span>

<span style="font-family:Times New Roman;font-size:18px;">var devscameratypeid = $("#camera_type input[name='camera_type1']:checked").val();//这里取出的是radio的value值
var devscameratype = $("#camera_type input[name='camera_type1']:checked").parent().text();//这里取出的是type为radio的input标签的文本</span>





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值