2017-07-19 3 views
0

enter image description here Ich bin neu bei jquery und javascript.please hilf mir, diesen Fehler zu beheben. Wenn Sie das Kontrollkästchen (mehr als 3 Mal) anklicken, hängen die Zellen mehrmals an. Danke im Voraus. Bitte hilf mir. * Seine Anfügen mehr die Zellen als einmalDuplizierung beim Anhängen der Zeilen in jquery

function suma() 
 
{ 
 
alert("hi"); 
 
$('#one').on("click", function(){ 
 
     $('#one input:checked').parent().parent().appendTo("#two"); 
 
     $("#two tr").append("<td> a </td>","<td> b</td>","<td> c</td>"); 
 
}); 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> 
 
</head> 
 
<body> 
 

 
<input type="submit" value="submit" onclick="suma()"/> 
 

 
<table id="one" border="1"> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>1</td> 
 
<td> 2</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 3</td> 
 
<td> 4</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 5</td> 
 
<td> 6</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>7</td> 
 
<td> 8</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>9</td> 
 
<td>10</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>11</td> 
 
<td>12</td> 
 
</tr> 
 

 
</table> 
 
<table id="two" border="1"> 
 
<th> msg1</th> 
 
<th> msg2</th> 
 
<th> msg3</th> 
 
<th> msg4</th> 
 
<th> msg5</th> 
 
<th> msg6</th> 
 
</table> 
 
</body> 
 
</html>

+2

einen besonderen Grund, warum Sie jQuery 1.3.1 verwenden? – Gerard

+0

Ist das ein funktionierendes Beispiel? die, die du gepostet hast? – incorelabs

+0

sagen Sie uns klar, was Sie suchen oder erwartete Antwort? – lalithkumar

Antwort

0

die Sie interessieren,

function suma() { 
    $('#one').on("click", function() { 
    var appendStr = "<td> a </td><td> b</td><td> c</td>"; 
    $('#one input:checked').parent().parent().wrap("<tr></tr>") 
             .append(appendStr).appendTo("#two"); 
    // add string inside TR and append the a b c then appendTo table. 
    }); 
} 

Arbeits example

Hoffnung hilft,

+0

Vielen Dank @Berkay – Raghavi

0

Nun, ich weiß nicht, warum Sie Ihre jquery Click-Ereignis innerhalb Funktion haben.

Ersetzen Sie Ihre Funktion mit diesem:

function suma(){ 
    $('#one input:checked').parent().parent().appendTo("#two"); 
    $("#two tr").append("<td> a </td>","<td> b</td>","<td> c</td>"); 
} 
0

Überprüfen Sie, ob die div (#TWO) nicht bereits in der Tabelle haben („# one“) fügen Sie es dann mit Suchfunktion dann prüfen, ob die Tabelle tut nicht haben diese tr dann fügen Sie es carful, dass Sie Tabelle abhängig davon hinzufügen, was mehr als eins mit der gleichen ID ergeben wird, so abhängig von der Klasse ist, bevorzugen.

function suma() 
{ 
alert("hi"); 
$('#one').on("click", function(){ 
if($("#two").find("#one")==0){ 
    $('#one input:checked').parent().parent().appendTo("#two"); 
} 
if($("#two").find("#one").find("<tr><td> a </td>","<td> b</td>","<td> c</td></tr>") ==0){ 
    $("#two").find("#one").append("<tr><td> a </td>","<td> b</td>","<td> c</td></tr>"); 
} 
}); 
} 
0

Sie benötigen zusätzlichen Text anhängen, dann nach Bedarf anhängen
Versuchen folgenden Code #TWO,

function suma() 
 
{ 
 

 
var row = $('#one input:checked').parent().parent().append("<td> a </td><td> b</td><td> c</td>"); 
 
    
 
row.appendTo("#two"); 
 
     
 

 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> 
 
</head> 
 
<body> 
 

 
<input type="submit" value="submit" onclick="suma()"/> 
 

 
<table id="one" border="1"> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>1</td> 
 
<td> 2</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 3</td> 
 
<td> 4</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 5</td> 
 
<td> 6</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>7</td> 
 
<td> 8</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>9</td> 
 
<td>10</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>11</td> 
 
<td>12</td> 
 
</tr> 
 

 
</table> 
 
<table id="two" border="1"> 
 
<th> msg1</th> 
 
<th> msg2</th> 
 
<th> msg3</th> 
 
<th> msg4</th> 
 
<th> msg5</th> 
 
<th> msg6</th> 
 
</table> 
 
</body> 
 
</html>

0

Ich denke, Sie sind für diese Suche.

$('#one').on("click", function(){ 
 
     $('#one input:checked').parent().parent().appendTo("#two"); 
 
     $("#two tr").append("<td> a </td>","<td> b</td>","<td> c</td>"); 
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
</head> 
 
<body> 
 

 
<input type="submit" value="submit" onclick="suma()"/> 
 

 
<table id="one" border="1"> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>1</td> 
 
<td> 2</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 3</td> 
 
<td> 4</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td> 5</td> 
 
<td> 6</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>7</td> 
 
<td> 8</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>9</td> 
 
<td>10</td> 
 
</tr> 
 
<tr> 
 
<td> <input type="checkbox"></td> 
 
<td>11</td> 
 
<td>12</td> 
 
</tr> 
 

 
</table> 
 
<table id="two" border="1"> 
 
<th> msg1</th> 
 
<th> msg2</th> 
 
<th> msg3</th> 
 
    
 
</table> 
 
</body> 
 
</html>

+0

@Raghavi Siehe nach Ihrem Bild seine Works Legen Sie einfach Ihre jquery 1.3.1 zu Jquery 2.1.1 –