1

我正在尝试实现一个动态表单,可以添加\删除字段(现在只需添加,因为它不起作用)。我正在使用 Symfony 2.0.13,并按照此处的指南进行操作, 但结果是我无法获得

<a href="#" class="add_tag_link">Add a tag</a>

在呈现的 html 中,如您在此处看到的 #2

有人有线索吗?

4

1 回答 1

1

只需将脚本更改为

jQuery(document).ready(function() {

 // Get the div that holds the collection of tags
var collectionHolder = $('ul.tags');

// setup an "add a tag" link
var $addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>');
var $newLinkLi = $('<li></li>').append($addTagLink);


    // add the "add a tag" anchor and li to the tags ul
    collectionHolder.append($newLinkLi);

    $addTagLink.on('click', function(e) {
        // prevent the link from creating a "#" on the URL
        e.preventDefault();

        // add a new tag form (see next code block)
        addTagForm(collectionHolder, $newLinkLi);
    });
});

这将工作......

于 2012-05-17T14:41:25.570 回答