我在视图中有一个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)');
答案 0 :(得分: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));
}