layui中的select下拉框,数据加载出来了,下拉框里面却没有数据,是什么原因?(已解决)

这个问题坑了我很久了。
错误显示:

在这里插入图片描述
我们可以看到竟然没有把数据添加进去。

在这里插入图片描述

当我们检查的时候数据是有的

在这里插入图片描述
但dl里的数据就没有了,说明是没有渲染出来。

解决方法:

看代码:

html代码:

 

<div class="layui-input-inline"  >
            <select name="quiz2" id="quiz2"  lay-filter="quiz2">
                  
            </select>
        </div>
js代码:


 function show(selectval) {
   
        $.get("/Home/selectContent?classificationName=" + selectval, function (data) {
   

            var content = '';
            content += '<option value="">请选择市</option>';
          
            for (var key in data) {
   
                var jsonstr = data[key];
              
                content += '<option value=\"' + jsonstr.contentName + '\">' + jsonstr.contentName + '</option>'
            }
           
            $("#quiz2").html(content);
            layui.form.render('select');  //这里就是我们要渲染的地方了
           
        });

    }

调用方法:

//选择框的点击事件

 form.on('select(select)', function (data) {
   
        var  txtval = data.elem[data.elem.selectedIndex].text;//获取选中的文本值。
        show(txtval);
          
    });

实现效果:

在这里插入图片描述

这解决了。

全网页代码:

@{
   
    ViewBag.Title = "trvalYouJi";
}
@using DAL_BJ
@{
   

    classification_dal classification_dal = new classification_dal();
    List<classification> classificationslist = classification_dal.classificationsist();
    content_dal _Dal = new content_dal()
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的美,让我痴迷

你的好,我会永远记住你的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值