我下面有一个功能可以正常工作:
function insertQuestion(form) {
var $tbody = $( #qandatbl > tbody );
var $tr = $("<tr class= optionAndAnswer align= center ></tr>");
var $noofanswers = $("<td class= noofanswers ></td>");
var $questionType = ;
$( .numberAnswerTxt , context).each(function() {
var $this = $(this);
var $noofanswersText = ;
if ($questionType == True or False || $questionType == Yes or No ) {
$noofanswersText = $("<span class= naRow string style= display: block; >Only 1 Answer</span><input type= text class= numberAnswerTxtRow answertxt style= display: none; onkeyup= numberKeyUp(this) onkeypress= return isNumberKey(event) onChange= getButtons() >").attr( name , $this.attr( name )).attr( value , $this.val());
}
else {
$noofanswersText = $("<span class= naRow string style= display: none; >Only 1 Answer</span><input type= text class= numberAnswerTxtRow answertxt style= display: block; onkeyup= numberKeyUp(this) onkeypress= return isNumberKey(event) onChange= getButtons() >").attr( name , $this.attr( name )).attr( value , $this.val());
}
$noofanswers.append($noofanswersText);
});
$tr.append($noofanswers);
$tbody.append($tr);
}
但我希望$noofanswers
包含在它自己的表行中,所以我将$noofansswers
更改为包含<;tr></tr>
,使代码:
var $noofanswers = $("<td class= noofanswers ></td>");
现在变成:
var $noofanswers = $("<tr><td class= noofanswers ></td></tr>");
但如果我这样做,那么$(.numberAnswerTxt,context).each(function(){
就不能正常工作。所以我的问题是,如果我添加<;tr>;
标记,那么我需要在函数中更改什么才能使其重新工作?