铁雪资源网 Design By www.gsvan.com

给代码添加如下部分:

layui.use('form', function(){ //此段代码必不可少
 var form = layui.form;
 form.render();
});

实现效果:

Layui动态生成select下拉选择框不显示的解决方法

HTML代码:

<div class="layui-form-item">
 <label class="layui-form-label">执行周期</label>
 <div class="layui-input-inline" style="width: 90px;">
  <select name="period_type" lay-verify="required" lay-filter="period">
   <option value="week">每星期</option>
   <option value="day">每天</option>
   <option value="day-n">N天</option>
   <option value="hour">每小时</option>
   <option value="hour-n">N小时</option>
   <option value="minute-n">N分钟</option>
   <option value="month">每月</option>
  </select>
 </div>
 <div id="suboption">
  <!-- 默认每星期 -->
  <div>
  <div class="layui-input-inline" style="width: 90px;">
   <select name="week">
    <option value="1">周一</option>
    <option value="2">周二</option>
    <option value="3">周三</option>
    <option value="4">周四</option>
    <option value="5">周五</option>
    <option value="6">周六</option>
    <option value="0">周日</option>
   </select>
  </div>
  <div class="layui-input-inline" style="width: 60px;">
   <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
  </div>
  <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
   <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
  </div>
  <div class="layui-input-inline" style="width: 60px;">
   <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
  </div>
  <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
   <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
  </div>
 </div>
 </div>

</div>
layui.use('form', function(){
 var form = layui.form;
 form.on('select(period)', function(data){
  var num = data.elem.selectedIndex; //获取对应option的索引排序
  num = num + 1;
  $('#suboption').empty();
  switch (num)
  {
   case 1: //每星期
    $("#suboption").append(`<div>
  <div class="layui-input-inline" style="width: 90px; height: 36px; font-size: 14px;" id="weekid" >
   <select name="week" style="height: 36px;">
    <option value="1">周一</option>
    <option value="2">周二</option>
    <option value="3">周三</option>
    <option value="4">周四</option>
    <option value="5">周五</option>
    <option value="6">周六</option>
    <option value="0">周日</option>
   </select>
  </div>
  <div class="layui-input-inline" style="width: 60px;">
   <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
  </div>
  <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
   <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
  </div>
  <div class="layui-input-inline" style="width: 60px;">
   <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
  </div>
  <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
   <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
  </div>
 </div>`);
    layui.use('form', function(){ //此段代码必不可少
     var form = layui.form;
     form.render();
    });
    break;
   case 2: //每天
    $("#suboption").append(` <div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
   case 3: //N天
    $("#suboption").append(` <div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="where1" value="3" max="31" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="天" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
   case 4: //每小时
    $("#suboption").append(`<div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
   case 5: //N小时
    $("#suboption").append(` <div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
   case 6: //N分钟
    $("#suboption").append(`<div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="3" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
   case 7: //每月
    $("#suboption").append(` <div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="where1" value="3" max="31" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="日" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="hour" value="1" max="23" maxlength="2" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="小时" style=" background-color: #f6f6f6;">
   </div>
   <div class="layui-input-inline" style="width: 60px;">
    <input type="number" name="minute" value="30" maxlength="2" max="59" min="0" class="layui-input"/>
   </div>
   <div class="layui-input-inline" style="width: 50px; vertical-align: middle; margin-left: -11px;">
    <input type="text" class="layui-input" readonly value="分钟" style=" background-color: #f6f6f6;">
   </div>
  </div>`);
    break;
  }
 });

});

以上这篇Layui动态生成select下拉选择框不显示的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
Layui,select,下拉选择框

铁雪资源网 Design By www.gsvan.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
铁雪资源网 Design By www.gsvan.com

评论“Layui动态生成select下拉选择框不显示的解决方法”

暂无Layui动态生成select下拉选择框不显示的解决方法的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。