Symfony jquery原型动态表单

symfony jquery prototype dynamic form

本文关键字:表单 动态 原型 jquery Symfony      更新时间:2023-09-26

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

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

在渲染的 HTML 中,如你在这里看到的 #2

有人知道吗?

只需将脚本更改为

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);
    });
});

这将起作用...