首页 \ 问答 \ 如何使用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;
    }
    }
    }

相关问答

更多
  • 来自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 ...
  • 你的解决方案本质上是 我正在尝试在对象阵列上使用二进制搜索。 我正在使用对象,因为对于一个实例,我可能有一组字符串或整数 这表明你应该使用泛型,而不是Object[] 。 如果这样做,则必须使用Integer[]而不是int[]因为Java泛型不适用于基本类型。 不需要编写compareTo方法,因为String和Integer已经实现了Comparable 。 我用T替换了Object (其中T extends Comparable )并且它正常工作。 该程序打印2应该。 public static ...
  • 将列表数组的类型更改为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 ...
  • 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 ...
  • 二分查找仅适用于有序列表。 但是你不要从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 ...
  • 像< , <= , >=和>类的比较运算符仅为数字类型定义。 要比较其他类型,您需要: 使用实现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]:

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)