<div class="panel panel-default">
    <div class="panel-body">
        <div class="text-right">
            <button class="btn btn-primary" id="submitSelect" type="button">
                <i class="fa fa-plus-square"></i>
                确定选择
            </button>
        </div>
        <select class="form-control" multiple id="selectQuestion">
            <?php foreach ($questions as $u): ?>
                <option value="<?= $u['id'] ?>"><?= $u['id'] ?>、<?= $u['name'] ?></option>
            <?php endforeach; ?>
        </select>
    </div>
</div>

<link rel="stylesheet" type="text/css" media="screen" href="<?= THEMEPATH ?>/css/bootstrap-duallistbox.min.css"/>

<script src="<?= THEMEPATH ?>/js/jquery.bootstrap-duallistbox.min.js"></script>

<script type="text/javascript">
    $(function () {
        var selected=$('[data-type=<?=$type?>]').find('input[type=hidden]');

        $.each($.parseJSON(selected.val()),function(k,v){
            $('option[value='+v+']').attr('selected','true');
        });

        $('#selectQuestion').bootstrapDualListbox({
            'infoText': false,
            'infoTextEmpty': false,
            'selectorMinimalHeight': $(document).height() - 425
        });

        $('#submitSelect').click(function () {
            var t=$('[data-type=<?=$type?>]').find('.num').val();
            var l=$('#selectQuestion').val().length;
            if (t < l) {
                show_error('选择的题目超出选题总数！');
                return false;
            }
            selected.val('['+$('#selectQuestion').val()+']');
            $('[data-type=<?=$type?>]').find('span b').text(l);
            ajax_dialog.close();
        });
    });
</script>