下拉列表的简单操作

<div class="row">
                                                <div class="col-md-2 pr0">
                                                    <small><span class="text-danger pad8">*</span>公司类型:</small>
                                                </div>
                                                
                                                <div class="col-md-4">
                                                    <select class="form-control" id="company">
                                                      <option>选择公司类型</option>
                                                      <option>有限公司</option>
                                                      <option>有限责任公司</option>
                                                      <option id="noN">暂无</option>
                                                    </select>
                                                </div>
                                                <div class="col-md-2">
                                                    <button class="btn btn-primary" id="addCompany" data-toggle="modal" data-target="#myModal">我要添加</button>
                                                </div>
                                                <!--添加公司类型-->
                                                <div class="modal fade mt200" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                                <h4 class="modal-title" id="myModalLabel">添加公司类型</h4>
                                                            </div>
                                                            <div class="modal-body">
                                                                <div class="row">
                                                                    <div class="col-md-2">
                                                                        <span class="b_font">公司类型:</span>
                                                                    </div>
                                                                    <div class="col-md-6">
                                                                        <input type="text" name="companyType" id="companyType" value="" class="form-control" placeholder="请输入公司类型"/>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                                <button type="button" class="btn btn-primary" data-dismiss="modal" id="hold">保存</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

其中一些为bootstrapd class注意引用的时候加上bootstrap的样式

$("#addCompany").click(function(){
            var text = $("#company option:selected").text();
            if(text!="暂无"){
                alert("请先选择暂无");
                return false;
            }else{
                return true;
            }
        });
        $("#hold").click(function(){
            var companyType = $("#companyType").val();
            $("#company").append("<option selected='selected'>"+companyType+"</option>");
        });

 希望可以帮到你!!!!!!

posted @ 2016-08-09 15:54  上官靖宇  阅读(172)  评论(0编辑  收藏  举报