我是两个表,例如表A和表B.当我选中表A上的复选框时,我能够附加到表B.我面临的问题是在删除表B中的行时。当我删除时行以相反的顺序一切正常。意味着从下到上删除。在表A中恢复了行。但是如果我以随机顺序删除,例如,我有三行,当我删除第一行时,它将恢复到表A,但第二行和第三行不会。如果我删除第二行后跟第一行。他们得到恢复,但第三排却没有。
附上截图:
表A. Screenshot 1
表B. Screenshot 2
以下是代码:
$(".delete-row").click(function(){
$('[name="sl"]').val('');
$(".hssl").empty();
table A -- $(".invt-do").find('input[name="ssl[]"]').each(function(index){
if($(this).is(":not(:checked)")){
table B --- $(".sltable tbody tr").eq(index).each(function(){
$(this).show();
$(this).find('input[name="ssl[]"]').prop("checked", false);
});
$(this).parents("tr").remove();
$(".hssl").append($(this).parents("tr"));
$(".hssl").find('input[name="ssl[]"]').prop("checked", true);
// $('.sltable tbody tr').eq(index).show();
//$(".sltable tbody").find('input[name="ssl[]"]').prop("checked", false);
}
});
$.ajax({
url:"<?php echo base_url(); ?>updateinvtunstock", //$("#mainsec").attr("action"),
type:"POST",
data:$("#dlvssl").serialize(),//only input
success: function(response){
$('#dlvdetails').modal('show');
},
error: function() {
swal("Oops", "We couldn't connect to the server!", "error");
}
});
});
不确定我做错了什么。
答案 0 :(得分:1)
首先在你的代码//Second Class
import java.util.Scanner;
public class TestStateInformation {
public static void main(String [] args) {
StateInformation states = new StateInformation();
String [][] state = states.getStateInfo();
//Inserting scanner & variable.
Scanner scanner = new Scanner(System.in);
while(true) {
//Prompt the user to input a state name.
System.out.println("Please enter a state or None to exit: ");
//Read the state entered by user, including leading/trailing white spaces.
String stateInfo = scanner.nextLine();
//If loop to end if None is entered.
if (stateInfo.equalsIgnoreCase("None")) {
break;
} else {
int position = getStatePosition(state, stateInfo);
if (position != -1) {
System.out.println("Bird: "
+ getBird(position, state)
+'\n' + "Flower: "
+ getFlower(position, state) + '\n');
}
if ((scanner.nextLine().equals("None"))) {
System.out.println("***** Thank you! *****" + '\n'
+ "A summary report for each State, Bird, and Flower is: "
+ '\n' + getState(position, state)+ ", "
+ getBird(position, state) + ", "+ getFlower(position, state)
+ '\n' + "Please visit our site again!");
}//end if loop for printing bird and flower of state entered by user.
}//End else loop
}//end if loop
}//end while loop
private static int getStatePosition(String state[][], String stateInfo) {
for (int i = 0; i < state.length; i++) {
if (stateInfo.equalsIgnoreCase(state[i][0])) {
return i;
}
}
return -1;
}
//Creates the position of the state name into [0]
private static String getState(int position, String [][] state) {
return state[position][0];
}
//Creates the position of the state bird into [1].
private static String getBird(int position, String [][] state) {
return state[position][1];
}
//Creates the position of the state bird into [2]
private static String getFlower(int position, String [][] state) {
return state[position][2];
}
}
中将返回输入的索引我认为每次都会返回0,所以只有第一行会隐藏 ..而不是行的索引
好的,让我们从删除按钮点击事件开始
点击删除按钮时
查看下一个代码
index
如果您仍然需要使用自己的编码方式,那么下一段代码就没有用了
$(".delete-row").click(function(){
$(".invt-do").find('input[name="ssl[]"]').each(function(){ //loop through table a inputs
if(this.checked){ // check if its checked
var Row_Index = $(this).closest('tr').index(); // get checked input row index
$(".sltable tbody tr").show().eq(index).hide(); // show all rows then hide/remove the same index from table b
$(this).closest("tr").remove(); // then remove the row from table a
}
});
});
你可以用下一个代码替换它而不用循环
$(".sltable tbody tr").eq(index).each(function(){
$(this).show();
$(this).find('input[name="ssl[]"]').prop("checked", false);
});