select默认赋值

提问 已结
4 504
小键子
小键子 2018-9-9
悬赏:20飞吻
<div class="flex-1">
<label class="layui-form-label">*公司名称</label>
<div class="layui-input-block">
<select name="companyName" required lay-verify="required" id="companyName" lay-filter="companySelect">
</select>
</div>
</div>
html是这样
js我获取到数据怎么默认加上select不用自己选中


还有就是layui做的iframe,刷新时父页面不刷新只刷新子页面
回帖
  • 拘魂者
    2018-9-10
    $("#companyName").val(value);
    form.render("select");
    刷新表格直接用reload不行么==
    0 回复
  • 代号007
    2018-9-10
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/src/css/layui.css" media="all">
    <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
    </head>
    <body>

    <script src="layui/src/layui.js"></script>

    <form class="layui-form" action="">
    <div class="layui-form-item">
    <label class="layui-form-label">选择框</label>
    <div class="layui-input-block tpl-select1">
    <script type="text/html" class="tpl">
    <select>
    <option value="">请选择</option>
    {{# layui.each(d.data,(i,row)=> { }}
    <option value="{{ row.id }}" {{# if(d.selected == row.id){ }}selected{{# } }}>{{ row.name }}</option>
    {{# }); }}
    </select>
    </script>
    </div>
    </div>
    </form>
    <script>
    layui.use(['form','laytpl','jquery'],(form,laytpl,$)=>{
    var d = {
    selected:1,
    data:[
    {id:1,name:'选择一'},
    {id:2,name:'选择二'},
    {id:3,name:'选择三'},
    ]
    };
    console.log(laytpl($('.tpl').html()))
    laytpl($('.tpl').html()).render(d,(html)=>{
    $('.tpl-select1').html(html);
    });
    form.render('select')
    });


    </script>
    </body>
    </html>
    1 回复
  • 代号007
    2018-11-21
     layui.use(['form','laytpl','jquery'],function(){
    var form = layui.form,laytpl = layui.laytpl,$ = layui.$

    });
    1 回复
  • ftong
    2018-11-20
    @代号007

    layui.use(['form','laytpl','jquery'],(form,laytpl,$)=>{
    能不能把箭头函数改成function,怎么改呢?
    0 回复