0

在我看来,我有一个 dropDownListFor,如下所示:

`@Html.DropDownListFor(x => x.idResponsaveis, Model.responsaveis)
 <input type='button' value='Adicionar' onclick='adicionarResponsavel()' class='btn' />`

我需要在用户单击 adicionarResponsavel() 时添加多个 dropDownList。

我的 JavaScript 代码是:

function adicionarResponsavel(){

        var div = document.getElementById('listaResponsaveis');
        var node = document.createElement('div');
        node.setAttribute('id', 'div' + quantity);
        node.appendChild('@Html.DropDownListFor(x => x.idResponsaveis, Model.responsaveis)');

        div.appendChild(node);

    }

有错误的具体行是:

node.appendChild('@Html.DropDownListFor(x => x.idResponsaveis, Model.responsaveis)');
4

1 回答 1

0

尝试使用 jQuery

function adicionarResponsavel(){

    var div = document.getElementById('listaResponsaveis');
    var node = document.createElement('div');
    node.setAttribute('id', 'div' + quantity);

   var existingDropDownClone=$('#id-of-existing-select-box').clone();

   existingDropDownClone.appendTo($(node));
}
于 2012-10-03T12:05:07.143 回答