使用链接的jQuery函数动态添加表单元素

时间:2013-03-08 17:23:40

标签: javascript asp.net-mvc-4 telerik-mvc

我有一个网站,用户可以在提交列表之前配置项目列表。每个项目由一行级联组合框表示(每个选项更新以下组合框中的可能值)。

用户可以根据需要添加任意数量的项目,进行配置,然后提交。

要进行添加操作,我有一个像这样的javascript函数:

function newAction() {
    // Get value of index so we can form our ids
    var index = $("#ItemTable").find("#Item").length;

    //copy the table row
    var newItemRow = $("#Item:last-of-type").clone(true);

    // Update all of the ids
    var rowTextBefore = newItemRow.html();
    var rowText = rowTextBefore.replace("[" + index - 1 + "]", "[" + index + "]");
    newItemRow.html(rowText);

    // Append the row to the end of the table
    $("#ItemTable").append(newItemRow);
}

这一切都很有效。

但是为了启用级联组合框,有一堆jQuery的东西可以为每一行生成。它看起来像这样:

jQuery(document).ready(function(){
    jQuery('#Items[0]_Name').tComboBox({highlightFirst:false,     
        cascadeTo:'Items[0]_Accessories', data:[{...data here...]});
    jQuery('#Items[0]_Accessories').tComboBox({highlightFirst:false, 
    // etc.
}

如何将这些东西与文档元素一起克隆,以便我动态添加的行也实现了级联组合框?

0 个答案:

没有答案