jquery version:1.8
Original code
<tr>
<td>1</td>
<td>11,12</td>
</tr>
<tr>
<td>2</td>
<td>21,22</td>
</tr>
changed to
<tr>
<td>1</td>
<td><a>11</a><a>12</a></td>
</tr>
<tr>
<td>2</td>
<td><a>21</a><a>22</a></td>
</tr>
Tried to add id="img" to <td>11,12</td>
, but $("#img").eq(1).html() cannot get it The content of the second line.
for(var i=0; $("#img").length; i++){
//$("#img").eq(i).html需要非空判断
var arr= $("#img").eq(i).html.spilt();
var str;
for(var j=0; aar.length; j++){
str = "<a>"+arr[j]+"</a>";
}
$("#img").eq(i).html(str);
}
I’m not very familiar with jQuery. I hope experts can help correct some grammatical errors, which is causing trouble for experts.
I don’t know if you are clearer, id is unique, and there can only be one same id name in an html code page! So code like
$("#img").eq(1)
definitely does not comply with the specification.Visually check your code and change it from adding id to adding class. There is no problem. In addition, you can use jquery's each method to traverse dom nodes:
id can only be unique, and can only get the first value, so use class