Layui开发下拉框及单选框radio回显

108次阅读

共计 848 个字符,预计需要花费 3 分钟才能阅读完成。

首先是下拉框的回显

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
$(“#worker”).each(function () {
    // this 代表的是 <option></option>,对 option 再进行遍历
    $(this).children(“option”).each(function () {
        // 判断需要对那个选项进行回显
        if (this.value == 2 {
            console.log($(this).text());
            // 进行回显
            $(this).attr(“selected”, “selected”);
        }
    });
    // 必须刷新表单
    form.render(‘select’);
});

其次是 radio 的单选框

JavaScript

1
2
3
// 将表单中的 radio 状态写到页面中
$(“input:radio[name=comefrom][value = 2]”).prop(“checked”, true);
form.render(‘radio’);

 

正文完
 0