添加新项目的功能 [英] Function for adding new items

查看:102
本文介绍了添加新项目的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有发票.订单项排列在一个表格中,基本上是这样的:

I have an invoice. Line items are arranged in a table, basically like this:

| product name (drop down select menu) | price | quantity | line total |

我有这个JavaScript文件: http://pastie.org/3021944 .

I have this JavaScript file: http://pastie.org/3021944.

如果我正在编辑发票,则通过从下拉菜单中选择其他产品来更改产品时,它将填充价格字段,发票的行总额和总计.该文件还会添加带有表单字段的新行,并删除表行.

If I'm editing an invoice, when I change the product by selecting a different one from the drop down menu, it populates the price field, the line total and the grand total of the invoice. That file also adds new rows with form fields and deletes table rows.

一切正常,直到我单击添加新行"以将新产品添加到发票.但是然后,仅在那些添加的行上,该新行的价格和总计不会更新,而只是空白.

Everything works fine, until I click on "Add a new line" to add a new product to the invoice. But then, only on those added rows, the price and grand total for that new line is not updated, it's just blank.

推荐答案

您需要将事件附加到 on(),以便自动添加动态添加的内容

You'll need to attach your events with on() so that dynamically added content is wired up automatically

我的防火墙阻止了您的链接,但是像这样:

My firewall is blocking your link, but something like this:

$(document).on("blur", ".someSelector", function() {
   //your handler
});

如果您使用的是jQuery 1.7,或者使用的是jQuery的较旧版本,则可以使用委托

if you're using jQuery 1.7, or, if you're on an older version of jQuery, you can use delegate

$(document).delegate(".someSelector", "blur", function() {
   //your handler
});

请不要不要使用实时直播,因为已弃用

Do not use live, since it's deprecated

这篇关于添加新项目的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆