Jquery для циклической обработки строк и ячеек таблицы, где checkob проверяется, объединяется
У меня есть таблица с несколькими строками. в таблице есть несколько столбцов с флажками. Мне нужно пройти через каждый из флажков, где он проверяется, объединить/присоединить вход от этой конкретной ячейки к другим входам из той же строки.
вы можете увидеть скрипку здесь:
http://jsfiddle.net/QS56z/10/
Как я могу, помимо цикла по строке, прокручивать каждый <td>
после того, как у меня есть этот <td>
, как я могу искать вход, имя которого начинается с x
в этом td. один раз обнаружил, что concatenate/присоединяется к входу от этого к входам в строке.
Надеюсь, это имеет смысл.
по существу:
Я хочу присоединиться к (семье) к (размеру) к (классу), где семья и класс находятся в одной строке, и в каждой строке есть несколько размеров. каждый результат должен быть записан в обрабатываемый TD.
Я добрался до этого момента, но застрял:
function createcodes(){
alert('running');
//run through each row
$('.authors-list tr').each(function(){
//processing this row
//how to process each cell(table td) where there is checkbox
$($(this).find('input[name^="line"]').val(
$('$(this).find('input[name^="family"]'').val() + ' ' + // common input(family) on row, use for all table cells(td)
$('#$(this).find('input[name^="size"]'').val() + ', ' + // this cells input called size, unique to this cell only
$('#$(this).find('input[name^="grade"]'').val() // common input(grade) on row, use for all table cells(td)
);
// end of cell row processing
});
//end of rows processing
}
Спасибо, как всегда.
http://jsfiddle.net/QS56z/10/
my html:
<table class="authors-list" border=1 id="ordertable">
<tr>
<td ><input type="text" id="product1" name="product1" class="rounded" value="38114CR"></td>
<td ><input type="text" size='5' id="qty1" name="qty1" class="rounded" value="10"/></td>
<td class="tdcheckbox">
<input type="checkbox" id="h09_1" name="h09_1" checked class="rounded"/>
<input type="text" id="line_1_09" name="line_1_09" >
<input type="text" id="size_1_09" name="size_1_09" value="09">
</td>
<td class="tdcheckbox">
<input type="checkbox" id="h12_1" name="h12_1" class="rounded"/>
<input type="text" id="line_1_12" name="line_1_12" value="">
<input type="text" id="size_1_12" name="size_1_12" value="12">
</td>
<td class="tdcheckbox">
<input type="checkbox" id="h15_1" name="h15_1" checked class="rounded"/>
<input type="text" id="line_1_15" name="line_1_15" >
<input type="text" id="size_1_15" name="size_1_15" value="15">
</td>
<td><input type="text" name="cubespercheck_1" id="cubespercheck_1" value="0" size=5></td>
<td><input type="text" name="skufamily_1" id="skufamily_1" value="38114"></td>
<td><input type="text" name="skugrade_1" id="skugrade_1" value="cr"></td>
</tr>
</table>
<input type="button" id="continue" value="continue">
помните, что существует несколько строк. Спасибо.
Ответы
Ответ 1
ОБНОВЛЕНО
Я обновил вашу демонстрацию: http://jsfiddle.net/terryyounghk/QS56z/18/
Кроме того, я изменил два ^=
на *=
. См. http://api.jquery.com/category/selectors/
Обратите внимание на селектор :checked
. См. http://api.jquery.com/checked-selector/
function createcodes() {
//run through each row
$('.authors-list tr').each(function (i, row) {
// reference all the stuff you need first
var $row = $(row),
$family = $row.find('input[name*="family"]'),
$grade = $row.find('input[name*="grade"]'),
$checkedBoxes = $row.find('input:checked');
$checkedBoxes.each(function (i, checkbox) {
// assuming you layout the elements this way,
// we'll take advantage of .next()
var $checkbox = $(checkbox),
$line = $checkbox.next(),
$size = $line.next();
$line.val(
$family.val() + ' ' + $size.val() + ', ' + $grade.val()
);
});
});
}
Ответ 2
Попробуйте следующее:
function createcodes() {
$('.authors-list tr').each(function () {
//processing this row
//how to process each cell(table td) where there is checkbox
$(this).find('td input:checked').each(function () {
// it is checked, your code here...
});
});
}