首页 \ 问答 \ jQuery不适用于动态添加的表格行(jquery doesn't work on dynamically added table rows)

jQuery不适用于动态添加的表格行(jquery doesn't work on dynamically added table rows)

所以我有一个表,其中用户将输入一些东西,在最后一列中,它将根据其他列的输入自动填充。 它工作得很好,但是一旦我在表中添加另一行,它不会像原始行那样填充最后一列。

所以我的问题是什么是错的,我该如何解决这个问题呢?

谢谢!

添加行的脚本:

$('.add_row_count').on('click',function(){
event.preventDefault();
var newRow = $('<tr><td style = "text-align: center;"><input type="text" name="categ_name[]" id="categ_name" value="" placeholder="Item Category" required></td> ' +
'<td style = "text-align: center;"><input type="number" name="beg_count[]" id="beg_count" value="" placeholder="BEG Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="del_count[]" id="del_count" value="" placeholder="DEL Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="ret_count[]" id="ret_count" value="" placeholder="RET Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="exc_count[]" id="exc_count" value="" placeholder="EXC Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="pout_count[]" id="pout_count" value="" placeholder="P-Out Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="sales_count[]" id="sales_count" value="" placeholder="SALES Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="end_count[]" id="end_count" value="" placeholder="END Count" required></td>' + 
'<td style = "text-align: center;"><input type="number" name="actual_count[]" id="actual_count" value="" placeholder="Actual Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="variance[]" id="variance" value="" placeholder="Variance" readonly></td>' +
'<td style="border-top: 1px solid white; border-bottom: 1px solid white; border-right: 1px solid white"><button class="del" id="delete_row_count" type="button" onclick="deleterow_count();">Delete row</button></td></tr>');
 $('table.count').append(newRow);
});

用于填充最后一列的脚本:

      $('#categ_name,#beg_count, #del_count, #ret_count,#exc_count, #pout_count, #sales_count,#end_count, #actual_count, #variance').keyup(function (){

  var end = $('#end_count').val();
  var ac = $('#actual_count').val();

  var total_variance = end - ac;


   $('#variance').val(total_variance);     
  });

小提琴: https//jsfiddle.net/qhk3ha75/3/


So I have a table wherein the user will input something and in the last column, it will be populated automatically based on the input of the other columns. It's working well enough but once i add another row to the table, it doesn't fill the last column like the original row does.

So my question is what's wrong and how can I fix this?

Thanks!

script for adding rows:

$('.add_row_count').on('click',function(){
event.preventDefault();
var newRow = $('<tr><td style = "text-align: center;"><input type="text" name="categ_name[]" id="categ_name" value="" placeholder="Item Category" required></td> ' +
'<td style = "text-align: center;"><input type="number" name="beg_count[]" id="beg_count" value="" placeholder="BEG Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="del_count[]" id="del_count" value="" placeholder="DEL Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="ret_count[]" id="ret_count" value="" placeholder="RET Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="exc_count[]" id="exc_count" value="" placeholder="EXC Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="pout_count[]" id="pout_count" value="" placeholder="P-Out Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="sales_count[]" id="sales_count" value="" placeholder="SALES Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="end_count[]" id="end_count" value="" placeholder="END Count" required></td>' + 
'<td style = "text-align: center;"><input type="number" name="actual_count[]" id="actual_count" value="" placeholder="Actual Count" required></td>' +
'<td style = "text-align: center;"><input type="number" name="variance[]" id="variance" value="" placeholder="Variance" readonly></td>' +
'<td style="border-top: 1px solid white; border-bottom: 1px solid white; border-right: 1px solid white"><button class="del" id="delete_row_count" type="button" onclick="deleterow_count();">Delete row</button></td></tr>');
 $('table.count').append(newRow);
});

script for populating the last column:

      $('#categ_name,#beg_count, #del_count, #ret_count,#exc_count, #pout_count, #sales_count,#end_count, #actual_count, #variance').keyup(function (){

  var end = $('#end_count').val();
  var ac = $('#actual_count').val();

  var total_variance = end - ac;


   $('#variance').val(total_variance);     
  });

fiddle: https://jsfiddle.net/qhk3ha75/3/


原文:https://stackoverflow.com/questions/40603460
更新时间:2023-08-24 08:08

最满意答案

A根本没有vtable(或者它不应该放在任何好的编译器上),因为它不是一个多态类:它没有虚拟成员函数。

函数show()只能在可执行文件中存在一次。 成员函数与普通非成员函数并没有太大区别,它们只是有一个额外的,隐含的参数。 您可以将其视为编译器将成员函数转换为类似的非成员函数,例如:

void show(A* this)
{
    if (this->x == 0)
        cout << "\nCalled by OBJ_1";
    else    
        cout << "\nCalled by OBJ_2";  
}

而不是OBJ_1.show() ,调用这个非成员函数的可比较方法是使用show(&OBJ_1)

每创建A对象都没有一个A::show() 。 总共有一个A::show()总数,它将其作为参数调用它的实例。


A does not have a vtable at all (or it shouldn't on any good compiler) because it is not a polymorphic class: it has no virtual member functions.

The function show() exists in the executable exactly once. Member functions aren't really different from ordinary nonmember functions, they just have an extra, implicit this parameter. You can think of it as if the compiler transforms a member function into a similar nonmember function, for example:

void show(A* this)
{
    if (this->x == 0)
        cout << "\nCalled by OBJ_1";
    else    
        cout << "\nCalled by OBJ_2";  
}

Instead of OBJ_1.show(), the comparable way to call this nonmember function would be to use show(&OBJ_1).

There isn't one A::show() per A object that is created. There's one A::show() total and it takes as an argument the instance on which it was called.

相关问答

更多
  • 虚拟功能如何在深层实现? 从“C ++中的虚拟函数” 无论何时一个程序都有一个声明的虚函数,就为该类构建了av-table。 v表由包含一个或多个虚拟函数的类的虚拟函数的地址组成。 包含虚拟函数的类的对象包含指向内存中虚拟表的基地址的虚拟指针。 每当有虚函数调用时,v表用于解析函数地址。 包含一个或多个虚拟函数的类的对象包含一个名为vptr的虚拟指针,位于内存中对象的最开头。 因此,在这种情况下,对象的大小会增加指针的大小。 该vptr包含内存中虚拟表的基址。 请注意,虚拟表是类特定的,即,类中只有一个虚拟 ...
  • A根本没有vtable(或者它不应该放在任何好的编译器上),因为它不是一个多态类:它没有虚拟成员函数。 函数show()只能在可执行文件中存在一次。 成员函数与普通非成员函数并没有太大区别,它们只是有一个额外的,隐含的参数。 您可以将其视为编译器将成员函数转换为类似的非成员函数,例如: void show(A* this) { if (this->x == 0) cout << "\nCalled by OBJ_1"; else cout << "\n ...
  • 语法 d->Derived::foo(); 将禁止虚拟调度并保证函数Derived::foo是被调用的函数,即使存在重写函数也是如此。 这很少是你想要的,但我不能建议其他解决方案,除非你解释为什么你要这样做。 例如,在给出的代码片段中,没有理由根据动态分配Derived 。 你可以写这个: Derived d; d.foo(); 这里,编译器确定动态类型是Derived ,因此不需要虚拟调度。 The syntax d->Derived::foo(); will suppress virtual di ...
  • 所以,对于所有看到这个问题并且现在不知道该怎么做的人: 我正在使用ollydbg,但您可以使用任何其他调试器/转储器。 最好的方法是将代码放入dll中。 确保执行你的函数,否则编译器不会编译它(至少对我来说) void OverrideFunction() { HMODULE hMod = GetModuleHandle("mydll.dll"); // If not loaded yet use LoadLibrary() IMyInterface *myObj = (IMyInterfa ...
  • 这里有不同的函数重载,不会覆盖定义的虚函数: virtual void sayHi() const {} virtual void sayHello() {} void sayHi() {} // non virtual function with a different signature (no const) void sayHello() const {} // non virtual function with a different signatuere (const) 如果要避免此类细微错 ...
  • 类中vtable成员的顺序没有明确定义。 实际上,您可以(并且将会!)在vtable指针之间找到数据成员。 如果您正在编写COM,那么在将其写入您将结果放入的指针之前,应该将其转换为要在QueryInterface返回的任何接口。即,类似于: HRESULT QueryInterface(REFIID riid, LPVOID *ppvObject) { if (*riid == IID_MY_INTERFACE) { *ppvObject = static_cast
  • struct many_vtable { void(*dtor)(void*); void(*print)(void const*,std::ostream&); }; templatestruct tag_t{}; templateconstexpr tag_t tag = {}; template many_vtable const* make_many_vtable(tag_t){ static const many_vt ...
  • 你可以用((Dog *)a) -> weight = 42.0; 或((Cat *)a) -> numberOfLives = 9; You can use ((Dog *)a) -> weight = 42.0; or ((Cat *)a) -> numberOfLives = 9;
  • 第一件事 - 标准对虚拟表没有任何说明。 它只涉及虚函数和多态。 允许每个编译器以其喜欢的任何方式实现此功能。 虚拟表只是虚函数的通用实现,它不是修饰,并且每个编译器的实现都不同。 最后,在我的Visual Studio 2015上,这个: class A1 { int x; void doIT(){} }; class A2 { int x; virtual void doIT(){} }; constexpr int size = sizeof(A1); conste ...
  • 向我们展示您正在使用的启动代码。 很可能你没有启用全局构造函数,这可以通过调用__libc_init_array()函数来完成。 您可以通过在main()的开头手动调用此函数来测试此理论 - 它应该可以正常工作。 如果是,则应将该函数添加到启动代码( Reset_Handler )。 快速测试: int main() { extern "C" void __libc_init_array(); __libc_init_array(); // rest of your code... ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • 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)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)