我有一个可以正常工作的函数:
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
包含在它自己的表格行中,所以我更改$noofanswers
为包含<tr></tr>
这样的代码:
var $noofanswers = $("<td class='noofanswers'></td>");
现在变成:
var $noofanswers = $("<tr><td class='noofanswers'></td></tr>");
但是,如果我这样做,那么$('.numberAnswerTxt', context).each(function() {
就不能正常工作。所以我的问题是,如果我添加<tr>
标签,那么我需要在函数中进行哪些更改才能让它再次工作?