首页
\
问答
\
如何使用jquery删除jsp中新添加的行中的先前行值(how to remove the previous rows values in the newly added rows in jsp using jquery)
如何使用jquery删除jsp中新添加的行中的先前行值(how to remove the previous rows values in the newly added rows in jsp using jquery)
我有一个单行的表,按钮添加和删除每一行....如果你按添加按钮然后它将添加新行,但问题是如果你用第一行填充一些值然后如果你按下添加按钮然后新的行与那些值.....我不想这样,新的行应该带有空值....任何人都可以解决这个问题吗???
<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript"> var tableSize=0; $(document).ready(function () { $('#btnAdd').click(function () { $clone_row = $('#FirstRow').clone(true); $clone_row.appendTo('#listfiles'); var row_len = $('#listfiles tr').length; var file_name = 'File ' + row_len + ':'; $clone_row.find('span.file_name').text(file_name); }); }); function deleteRow(btn) { tableSize = $('#listfiles tr').length; if (tableSize > 1) { $(btn).parent().parent().remove(); $('#listfiles tr').each(function (i) { var index = i + 1; $('td:first .file_name', this).text('File ' + index + ':'); }) } } </script> </head> <body> table id="listfiles"> <tr id="FirstRow"> <td> <span class="file_name">File 1:</span> <input type="file" name="filename" id="filename" value="xyz" />Description: <input type="text" name="description" id="filename" value="" /> <a href="#" onclick="deleteRow(this);">DeleteFile</a> </td> </tr> </table> <a href="#" id="btnAdd">Add additional file</a> </body> </html>
i have a table with single row and with the buttons add and remove along with each row....if you press add button then it will add new row but the problem is if you fill the 1st row with some values and then if you press the add button then the new row coming with that values.....i dont want like that,,the new rows should come with empty values....can any one resolve this???
<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript"> var tableSize=0; $(document).ready(function () { $('#btnAdd').click(function () { $clone_row = $('#FirstRow').clone(true); $clone_row.appendTo('#listfiles'); var row_len = $('#listfiles tr').length; var file_name = 'File ' + row_len + ':'; $clone_row.find('span.file_name').text(file_name); }); }); function deleteRow(btn) { tableSize = $('#listfiles tr').length; if (tableSize > 1) { $(btn).parent().parent().remove(); $('#listfiles tr').each(function (i) { var index = i + 1; $('td:first .file_name', this).text('File ' + index + ':'); }) } } </script> </head> <body> table id="listfiles"> <tr id="FirstRow"> <td> <span class="file_name">File 1:</span> <input type="file" name="filename" id="filename" value="xyz" />Description: <input type="text" name="description" id="filename" value="" /> <a href="#" onclick="deleteRow(this);">DeleteFile</a> </td> </tr> </table> <a href="#" id="btnAdd">Add additional file</a> </body> </html>
原文:https://stackoverflow.com/questions/20261821
更新时间:2023-04-29 07:04
最满意答案
public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); int A[]=new int[15]; System.out.println("Input an array of 15 elements in descending order"); for(int i=0;i<15;i++) { int j=Integer.parseInt(br.readLine()); A[i]=j; } System.out.println("Input the number to be searched"); int n=Integer.parseInt(br.readLine()); System.out.println("Press 1 for Binary search"); System.out.println("Press 2 for linear search"); int ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: { int flag=0,low,up,mid=0; low=0; up=14; int count = 0; mid=(low+up)/2; while(low<=up) { if(n>A[mid]){ mid--; } else if(n<A[mid]){ mid++; } else { flag=1; break; } count++; } System.out.println(count); if(flag==1) System.out.println("Element at position"+(mid+1)); else System.out.println("Element not found"); break; } } }
public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); int A[]=new int[15]; System.out.println("Input an array of 15 elements in descending order"); for(int i=0;i<15;i++) { int j=Integer.parseInt(br.readLine()); A[i]=j; } System.out.println("Input the number to be searched"); int n=Integer.parseInt(br.readLine()); System.out.println("Press 1 for Binary search"); System.out.println("Press 2 for linear search"); int ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: { int flag=0,low,up,mid=0; low=0; up=14; int count = 0; mid=(low+up)/2; while(low<=up) { if(n>A[mid]){ mid--; } else if(n<A[mid]){ mid++; } else { flag=1; break; } count++; } System.out.println(count); if(flag==1) System.out.println("Element at position"+(mid+1)); else System.out.println("Element not found"); break; } } }
相关问答
更多-
二进制搜索算法中的java.lang.StackOverflowError(java.lang.StackOverflowError in Binary Search Algorithm)[2023-01-24]
来自search(31, arr, 1, 30)你会遇到 1,30 15,30 22,30 26,30 28,30 29,30 29,30 29,30 .... 并成为无限stackOverFlow 所以你的算法应该是 public static boolean search(int value, int[] data, int start, int end) { int len = end - start + 1 ; int mid = (start + end) / 2; if ... -
public class BinarySearchTree
> 在你的情况T中,一个正式的泛型参数列出了一个类是一个有效的T所需要的。在你的情况中,你曾经说过,“要成为一个有效的T,类必须实现Comparable”(关键字是“extends “,但实际上这意味着”扩展或实现“。) 在你的实例中,T是学生。 如果我们用学生替代T: public class BinarySearchTree ... -
二进制搜索比较Java(Binary Search CompareTo Java)[2021-12-14]
你的解决方案本质上是 我正在尝试在对象阵列上使用二进制搜索。 我正在使用对象,因为对于一个实例,我可能有一组字符串或整数 这表明你应该使用泛型,而不是Object[] 。 如果这样做,则必须使用Integer[]而不是int[]因为Java泛型不适用于基本类型。 不需要编写compareTo方法,因为String和Integer已经实现了Comparable 。 我用T替换了Object (其中T extends Comparable)并且它正常工作。 该程序打印2应该。 public static ... -
用Java进行二进制搜索(Binary Searching in Java)[2023-12-14]
将列表数组的类型更改为Double private Double[] list; 您正在尝试将列表转换为数组,但将目标数组数据类型传递为double但它的int。 来自docs Collection.toArray(T [] a) 返回一个包含此collection中所有元素的数组; 返回数组的运行时类型是指定数组的运行时类型。 Change the type of list array to Double private Double[] list; you are trying to cast li ... -
Java二进制搜索错误(Java-Binary Search Error)[2021-11-24]
public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); int A[]=new int[15]; System.out.println("Input an array of 15 elements in descending order"); for(int i=0 ... -
二进制搜索的逻辑(Logic of binary search)[2023-05-28]
二分查找仅适用于有序列表。 但是你不要从std::cin得到你的列表,因此你的二分搜索会得到错误的结果。 要解决这个问题,您必须将输入限制为预先排序的列表,或者在进行二分搜索之前,您必须首先排序列表。 The binary search only works for ordered lists. But you don't order the list you get from std::cin, therefore you get wrong results from your binary search ... -
错误在其他地方(你的功能几乎完全正确): 你的树不平衡! 你必须做的更正是插入功能。 一个简单的插入函数只会创建一个像树一样的链表,因为如果按“升序”顺序插入元素,它们总是只添加到“左”或右。 栈的空间有限,所以如果你有一棵平衡树,它可以有40亿个节点,它的最大高度仍然是32.但是如果你的树即使节点很少(1000)也不平衡,它可能会发生堆栈溢出。 我也建议首先检查null(这不是你的问题,把它作为一个免费的错误修复) if(tree==null || tree.val == value ) The err ...
-
Java通用二进制搜索树无法比较T类型[重复](Java Generic Binary Search Tree cannot compare T types [duplicate])[2020-02-07]
像< , <= , >=和>类的比较运算符仅为数字类型定义。 要比较其他类型,您需要: 使用实现Comparable的类型,例如String 。 您可以通过向类型变量添加约束来完成此操作: public class Tree> 这意味着您可以调用compareTo方法: if (element.compareTo(current.element) < 0) { 传入Comparator ,它能够比较类型的实例: public boolean insert( ... -
因此,最大的问题是您忽略了数据类型。 insert函数返回int但是每当你指定它的返回值或者甚至在这个函数中返回一些东西时,你使用的变量都是指针 - 所以将insert返回类型改为struct Node *node 。 另外,在case 4部分的case 4 ,你使用函数printInoder ,它在调用之后声明和定义(在main函数下面),这就是为什么它警告你至少应该在main之前声明这个函数。 最后,在insert函数中,你调用newNode但是这个函数叫做NewNode ,它也在main声明和定义。 ...
-
您正在检查索引midpoint的值,而不是数组中的值。 if value == midpoint: 应该是: if value == alist[midpoint]: You're checking the value against the index midpoint and not the values in the array. if value == midpoint: Should instead be: if value == alist[midpoint]: