jQuery的表AddRow插件将ID号为添加的行插件、jQuery、AddRow、ID

由网友(呆橘)分享简介:行,所以我有一个表格,我使用jQuery表AddRow插件动态地添加行到表,问题是我想,当你选择一个菜单项的菜单项进入的文本框中以它的左侧。它的工作原理的第一行上,但我不知道如何得到它与通过插件添加的行工作。OK so I have a form and I'm using the jQuery Table AddR...

行,所以我有一个表格,我使用jQuery表AddRow插件动态地添加行到表,问题是我想,当你选择一个菜单项的菜单项进入的文本框中以它的左侧。它的工作原理的第一行上,但我不知道如何得到它与通过插件添加的行工作。

OK so I have a form and I'm using the jQuery Table AddRow plugin to dynamically add rows to a table, the problem is I'm trying to when you select a Menu Item that the menu item goes into the text box to the left of it. It works on the first row but I can't figure out how to get it to work with rows that are added via the plugin.

您可以看到我的code在这里的行动: http://jsfiddle.net/VXNzd/

You can see my code in action here: http://jsfiddle.net/VXNzd/

下面是jQuery的code:

Here is the jQuery code:

// This moves the select box text to the input box
$('#mnu_names').change(function() {
    var mnuProduct = $("#mnu_names").find(':selected').text();
    var mnuCleanProduct = mnuProduct.split(' - ');
    $('#topping_name').attr('value', mnuCleanProduct[0]);
});
// This code is needed to add and delete rows with the plugin
$(".toppings_add").btnAddRow({

这可能是更容易地看到通过访问的jsfiddle联系起来顶端我在说什么。当它加载使用选择框,选择什么,它会把这些信息通过在文本框中没有价格信息。添加一个新的行并再次尝试。将无法工作,无法弄清楚如何使它发挥作用。谢谢

It may be easier to see what I'm talking about by visiting the jsfiddle link up top. When it loads use the select box to and select something, It will put that info over into the text box without the price info. Add a new row and try it again. Won't work, can't figure out how to make it work. Thanks

推荐答案

这个问题是由tomhallam您的ID的说不是唯一的。此外 $。改变()上不加你跑了,经过块工作。您应该改用 $。在('改变',...)

The problem was as said by tomhallam your ID's are not unique. Also $.change() does not work on blocks added after you ran that. You should instead use $.on('change',...).

我更新了code和张贴在 http://jsfiddle.net/PDPbn/5/ 。

I updated your code and posted it on http://jsfiddle.net/PDPbn/5/.

修改后的jquery- code的情况如下:

The modified jquery-code goes as follows:

$(document).on('change','.mnu_names',function() {
    var mnuProduct = $(this).find(':selected').text();
    var mnuCleanProduct = mnuProduct.split(' - ');
    $(this).parentsUntil('tbody').find('.topping_name').attr('value', mnuCleanProduct[0]);
});
阅读全文

相关推荐

最新文章