类似这里添加行的value永远是questionNaireQuestion.option1 , value="${questionNaireQuestion.option1 }"
能否达到这样的效果: value="${questionNaireQuestion.'+(phName)+' }",这样的写法是错误的,改如何写达到如此的效果
function add(){
var val = $('#limit').val();
var lastInput = $('#contain input:last');
var phName = lastInput.attr('placeholder');
phName = phName.replace("选项","");
phName = parseInt(phName,10)+1;
if(parseInt(val,10)>=parseInt(phName,10)){
$('<div class="inputs"><input input type="text" id="option" name="option'+(phName)+'" value="${questionNaireQuestion.option1 }" maxlength="30" style="width: 80% " placeholder="选项'+phName+' " /><span onclick=del(this)>删除</span></div>').insertAfter(lastInput.parent('div'));
}else{
alert('超出了最大项');
}
}
<tr id="tr">
<td class="table_th" >题目选项:
<td width="" id="contain">
<div class='inputs'>
<input type="text" id="option1" name="option1"
maxlength="30" style="width: 80%" placeholder="选项1" value="${questionNaireQuestion.option1 }"/><font
color="red"> *</font></div>
<div class='inputs'><input type="text" id="option2" name="option2"
maxlength="30" style="width: 80%"" placeholder="选项2"value="${questionNaireQuestion.option2 }" /> </div>
<div class='inputs'><input type="text" id="option3" name="option3"
maxlength="30" style="width: 80% " " placeholder="选项3"value="${questionNaireQuestion.option3 }" /><span onclick=del(this)>删除</span></div>
<div class='inputs'><input type="text" id="option4" name="option4"
maxlength="30" style="width: 80% " placeholder="选项4" value="${questionNaireQuestion.option4 }"/><span onclick=del(this)>删除</span></div>
<div><a href="javascript:;" class="addRow" id="addRow" onclick="javascript:add()">+添加选项</a></div>
</td>
</tr>