Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击table td input,每次追加相同的tr_Javascript_Jquery - Fatal编程技术网

Javascript 单击table td input,每次追加相同的tr

Javascript 单击table td input,每次追加相同的tr,javascript,jquery,Javascript,Jquery,我在JavaScript中遇到了一个问题,当我单击td元素时,重复相同的tr。 我的html代码如下: <table id="tabl2" class="table time-table table-bordered table-striped budrow"> <thead> <tr> <th class="cal-head">Rates</th> <th class="cal-head"

我在JavaScript中遇到了一个问题,当我单击td元素时,重复相同的tr。 我的html代码如下:

<table id="tabl2" class="table time-table table-bordered table-striped budrow">
<thead>
    <tr>
        <th class="cal-head">Rates</th>
        <th class="cal-head">Start date</th>
        <th class="cal-head">End date</th>
    </tr>
</thead>
<tr>
    <td>
        <input type="number" readonly placeholder="Rates">
    </td>
    <td>
        <input type="text" readonly id="start" placeholder="Start date">
    </td>
    <td>
        <input type="text" class="datepicker" name="enddate" placeholder="End date">
    </td>
</tr>

费率
开始日期
结束日期

我尝试使用此js,但失败:

$('.budrow').click(function(){
   $(this).find('tr').append('<tr> <td></td> <td></td> <td></td> </tr>');
});
$('.budrow')。单击(函数(){
$(this.find('tr')。append('');
});

请帮助我。

将单击事件绑定到单击的元素,使用
最近的()
选择当前行,然后使用
after()
函数追加新行:

$('.btn')。在('click',function()上{
var,该值=$(此值);
var newRow='这是一个新行';
(newRow)之后的最近('tr');
});

点击
点击
点击

将单击事件绑定到单击的元素,使用
最近的()
选择当前行,然后使用
after()
函数追加新行:

$('.btn')。在('click',function()上{
var,该值=$(此值);
var newRow='这是一个新行';
(newRow)之后的最近('tr');
});

点击
点击
点击

将单击事件绑定到单击的元素,使用
最近的()
选择当前行,然后使用
after()
函数追加新行:

$('.btn')。在('click',function()上{
var,该值=$(此值);
var newRow='这是一个新行';
(newRow)之后的最近('tr');
});

点击
点击
点击

将单击事件绑定到单击的元素,使用
最近的()
选择当前行,然后使用
after()
函数追加新行:

$('.btn')。在('click',function()上{
var,该值=$(此值);
var newRow='这是一个新行';
(newRow)之后的最近('tr');
});

点击
点击
点击

您可以克隆并添加新行,另外最好单独使用“添加”按钮

<button class="budrow">Add</button>
<table id="tabl2" class="table time-table table-bordered table-striped budrow">
    <thead>
        <tr>
            <th class="cal-head">Rates</th>
            <th class="cal-head">Start date</th>
            <th class="cal-head">End date</th>
        </tr>
    </thead>
    <tr>
        <td>
            <input type="number" readonly placeholder="Rates" />
        </td>
        <td>
            <input type="text" readonly id="start" placeholder="Start date" />
        </td>
        <td>
            <input type="text" class="datepicker" name="enddate" placeholder="End date" />
        </td>
    </tr>
</table>

演示:

您可以克隆并添加新行,另外最好单独使用“添加”按钮

<button class="budrow">Add</button>
<table id="tabl2" class="table time-table table-bordered table-striped budrow">
    <thead>
        <tr>
            <th class="cal-head">Rates</th>
            <th class="cal-head">Start date</th>
            <th class="cal-head">End date</th>
        </tr>
    </thead>
    <tr>
        <td>
            <input type="number" readonly placeholder="Rates" />
        </td>
        <td>
            <input type="text" readonly id="start" placeholder="Start date" />
        </td>
        <td>
            <input type="text" class="datepicker" name="enddate" placeholder="End date" />
        </td>
    </tr>
</table>

演示:

您可以克隆并添加新行,另外最好单独使用“添加”按钮

<button class="budrow">Add</button>
<table id="tabl2" class="table time-table table-bordered table-striped budrow">
    <thead>
        <tr>
            <th class="cal-head">Rates</th>
            <th class="cal-head">Start date</th>
            <th class="cal-head">End date</th>
        </tr>
    </thead>
    <tr>
        <td>
            <input type="number" readonly placeholder="Rates" />
        </td>
        <td>
            <input type="text" readonly id="start" placeholder="Start date" />
        </td>
        <td>
            <input type="text" class="datepicker" name="enddate" placeholder="End date" />
        </td>
    </tr>
</table>

演示:

您可以克隆并添加新行,另外最好单独使用“添加”按钮

<button class="budrow">Add</button>
<table id="tabl2" class="table time-table table-bordered table-striped budrow">
    <thead>
        <tr>
            <th class="cal-head">Rates</th>
            <th class="cal-head">Start date</th>
            <th class="cal-head">End date</th>
        </tr>
    </thead>
    <tr>
        <td>
            <input type="number" readonly placeholder="Rates" />
        </td>
        <td>
            <input type="text" readonly id="start" placeholder="Start date" />
        </td>
        <td>
            <input type="text" class="datepicker" name="enddate" placeholder="End date" />
        </td>
    </tr>
</table>
演示:

尝试使用:

var $table = $('#tabl2');
$table.click(function(e){
   var $tr = $(e.target).closest('tr');
   if (($tr.parent().prop("tagName") != 'THEAD') && $tr.is(":last-child"))
       $tr.after($tr.clone());
});
.

尝试使用:

var $table = $('#tabl2');
$table.click(function(e){
   var $tr = $(e.target).closest('tr');
   if (($tr.parent().prop("tagName") != 'THEAD') && $tr.is(":last-child"))
       $tr.after($tr.clone());
});
.

尝试使用:

var $table = $('#tabl2');
$table.click(function(e){
   var $tr = $(e.target).closest('tr');
   if (($tr.parent().prop("tagName") != 'THEAD') && $tr.is(":last-child"))
       $tr.after($tr.clone());
});
.

尝试使用:

var $table = $('#tabl2');
$table.click(function(e){
   var $tr = $(e.target).closest('tr');
   if (($tr.parent().prop("tagName") != 'THEAD') && $tr.is(":last-child"))
       $tr.after($tr.clone());
});

.

请检查此链接请检查此链接请检查此链接请检查此链接谢谢蔡少江,其作品..但希望tr仅在我单击最后一个tr td元素时附加..不是每个tr..谢谢蔡少江,,它的作品..但是想要tr只会在我点击最后一个tr td元素时追加..不是每个tr..谢谢蔡少江,它的作品..但是想要tr只会在我点击最后一个tr td元素时追加..不是每个tr..谢谢蔡少江,它的作品..但是想要tr只会在我点击最后一个tr td元素时追加..不是每个tr。。