jQuery का उपयोग करके, मैं नीचे दी गई उदाहरण तालिका में मनमानी तालिका कक्ष का कॉलम इंडेक्स कैसे पा सकता हूं, जैसे कि एकाधिक कॉलमों में फैले सेल कई इंडेक्स हैं?तालिका का उपयोग करते हुए कॉलम इंडेक्स ढूँढना जब तालिका में कॉलम-स्पैनिंग सेल होते हैं
var index = 0;
cell.parent('tr').children().each(
function(idx,node) {
if ($(node).attr('colspan')) {
index+=parseInt($(node).attr('colspan'),10);
} else {
index++;
}
return !(node === cell[0]);
}
);
console.log(index);
यह शायद मतलब था एक प्लगइन के रूप में या विस्तार के माध्यम से यह करने के लिए:
एचटीएमएल
<table>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td id="example1">Three</td>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
<tr>
<td colspan="2">One</td>
<td colspan="2">Two</td>
<td colspan="2" id="example2">Three</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
</tbody>
</table>
jQuery
var cell = $("#example1");
var example1ColIndex = cell.parent("tr").children().index(cell);
// == 2. This is fine.
cell = $("#example2");
var example2ColumnIndex = cell.parent("tr").children().index(cell);
// == 2. It should be 4 (or 5, but I only need the lowest). How can I do this?
मुझे लगता है कि आपको अपने आप कुछ लिखना होगा (जैसे सेठ नीचे किया गया था)। हालांकि, पंक्तियों से सावधान रहें, जो आपकी गणना को और अधिक कठिन बना देगा। – aquinas
@Aquinas - rowspans ... ewww। – seth
इस कोड ने मेरी खोज में मेरी मदद की! – mjbates7