<h2>添加特色</h2>
<label for="feature">特色：</label>
<input id="feature" type="text">
<input type="submit" id="submit" class="button">
<h2>特色列表</h2>
<table class="table">
    <thead>
    </thead>
    <tbody>
    {% for item in result %}
    {% if loop.index0%4 == 0%}
    <tr>
    {% endif %}
        <td>{{ item.name }}</td>
    {% if loop.index0%4 == 3%}
    </tr>
    {% endif %}
    {% endfor %}
    </tbody>
</table>
<script>
    var admin_url = '{{ admin_url }}';
    (function ($) {
        $(document).ready(function () {
            $('#submit').click(function () {
                var name = $('#feature').val();
                if (name.trim() != '') {
                    $.ajax({
                        type: 'POST',
                        url: '{{ url }}/wp-admin/admin-ajax.php/',
                        data: 'action=add_feature&name=' + name,
                        success: function (data) {
                            switch (data.code) {
                                case 2000:
                                    window.location.href = admin_url + 'admin.php?page=add_feature';
                                    break;
                                case 2001:
                                    alert('不能重复添加特色');
                                    break;
                                default:
                                    break;
                            }
                        }
                    });
                } else {
                    alert('请输入特色');
                }
            });
        });
    })(jQuery);
</script>