Update: Das ist jetzt nichts, wie Sie Ihren Code, aber es wird ermöglicht es Ihnen, dynamisch Elemente aus strm Array einfügen in <td></td>
ABER die td muss Klasse mo haben - wie so <td class="mo" id="mo_1"></td>
Sie die Ids halten kann du hast. Sie stören den Code nicht.
Eine Erklärung: Ich benutze die jQuery.each() "$.each(function(){})
" -Funktion, um durch jedes HTML-Element, das 'class = "mo" hat, durch Einfügen der entsprechenden Strm-Array-Element, wie die Funktion fortschreitet, bis es keine gibt mehr mo's in der Objektliste. Auf diese Weise können Sie so viele Elemente mit den Elementen mo und strm hinzufügen, wie Sie möchten, ohne irgendeinen jquery-Code ändern zu müssen.
$(document).ready(function() { // encapsulate all functions in document ready function
// this is the strm array, in order to have a proper array you must have values inside "value" separated by ,
var strm = ["111", "201", "345", "434", "532", "677", "790", "890", "989", "118", "107", "136", "125", "153", "142"];
// execute mo, pass strm array to function.
mo(strm);
// mo function with array as input value
function mo(array) {
// jQuery.each() method.
// pass array as input value.
$.each(array, function(i, val) { // << index and value of each item in strm array
// if i is less than or equal to the number of elements with class mo,
if (i <= $(".mo").length) {
// get element with class mo equal to strm array index, insert value
$(".mo").get(i).append(val);
}
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tbl" class="tbl1">
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_0">
</td>
</tr>
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_1">
</td>
</tr>
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_2">
</td>
</tr>
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_3">
</td>
</tr>
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_4">
</td>
</tr>
<tr>
<th>
mobileno
</th>
<td class='mo' id="mo_5">
</td>
</tr>
</table>
Sie $ versucht ("# mo _" + i) statt $ ("# mo_1") ?? –
Was ist das folio() wo es definiert ist? – Parithiban
Sind Sie besonders daran interessiert, wie Sie Ihr Javascript geschrieben haben? Ich kann mir ein paar einfachere Wege vorstellen, um dies zu erreichen, indem ich dynamischere Funktionen zur Verfügung stelle. – Inkdot