<table class="form-table">
    <tbody>
    <tr>
        <th><label for="feature">房源特色</label></th>
        <td>
            <div id="feature" class="row">
            </div><br/>
            <button type="button" class="button action" data-toggle="modal" data-target="#houseFeature" id="featureBt">
                添加特色
            </button>
        </td>
    </tr>
    </tbody>
</table>

<script>
    (function($){
        {% if featureOld %}
            var data = {{ featureOld }};
            $.each(data,function(i,item){
                addFeature(item.tag_id,item.name);
            });
        {% endif %}
        $(document).ready(function(){
            //显示选中的特色
            $("#featureList").find("tr > td").click(function(){
                addFeature($(this).attr("id"),$(this).text());
            });
            existsCancel();
        });
    function addFeature(id,name){
        var houseFeature = $("<input>").attr({"type":"hidden","name":"data[houseFeature][]","value":id});
        var cancel = $("<span>").attr("aria-hidden","true").addClass("glyphicon glyphicon-remove featureCancel ");
        var span = $("<span>").attr("style","margin-right:5px").append(name);
        var divCol =$("<div>").append(houseFeature).append(span).append(cancel).addClass("col-md-3").attr("style","margin-bottom:10px");
        $("#feature").append(divCol);
    }
    })(jQuery);

</script>