bootstrap动态拼接下拉框

本文介绍了一种在Web应用中实现动态下拉菜单的方法,通过Ajax调用后端接口获取数据并实时更新二级分类下拉框,确保用户界面的响应性和数据的准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<div class="control-group">
			<label class="control-label">二级分类:</label>
			<div class="controls">
				<form:select path="subCategoryId" id="subCategoryId" class="input-medium">
                    <%-- <form:options items="${fns:getNavigationList(deskId)}" itemLabel="name" itemValue="id" htmlEscape="false"/> --%>
                </form:select>
			    <span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
//动态调用赋值下拉框
function categoryChange(){
	    	var id = $("#categoryId").val();
            $("#subCategoryId").html('');
            $("#subCategoryId").val('');
            $.ajax({
                url : '${ctx}/categoryinfo/categoryInfo/getCategorySon',
                type : "post",
                data : {
                    id : id
                },
                cache : false,
                error : function() {
                },
                success : function(data) {
                    
                    var optionstr = "";
                    var va="";
                    var list = data.list;
                    if (list && list.length != 0) {
                        $.each(list, function(index, item) {
                            optionstr+="<option value=\""+item.id;
                            optionstr+="\"";
                            if(index==0){
                                optionstr += " selected=\"selected\" "; //默认选中
                                va=item.name;
                            }
                            optionstr+=" >"+item.name+ "</option>";
                         });
                        $("#subCategoryId").append(optionstr);
                    }
                    $("#s2id_subCategoryId span.select2-chosen").eq(0).text(va);
                }
            });
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值