Home < select>标签的回显
Post
Cancel

< select>标签的回显

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<div class="form-group">
    <label class="col-sm-2" contenteditable="true" for="test">数字</label>
    <div class="col-xs-12">
        <select id="num" class="num" name="num">
            <option value="00" />
            <option value="01">01</option>
            <option value="02">02</option>
            <option value="03">03</option>
        </select>
    </div>
</div>

<script>
    var num = ${ json }.dateMap.num;
    var num_el = $("#num").find("option");
    for (var i = 0; i < num_el.length; i++) {
        var num_val = num_el.eq(i).val();
        if (num_val == num) {
            num_el.eq(i).attr("selected", true);
        }
    }
</script>
This post is licensed under CC BY 4.0 by the author.