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 に答える