如何添加动态jQuery的按钮? [英] How to add dynamic jquery button?

查看:133
本文介绍了如何添加动态jQuery的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我使用jQuery添加和DELET行的表。我也使用jQuery用户界面来呈现按钮。

I have a table where I use jquery to add and delet rows. I also use jquery ui to render buttons.

当我添加一个新行,我也是在一个单元格添加一个按钮,但是这个人是不是渲染。

When I add a new row, I also add a button in a cell, but this one is not rendered.

var tdata = "<tr>";
tdata += "<td align=\"right\">my data</td>";
tdata += "<td align=\"left\">";
tdata += "<button class=\"delete\">delete</button>";
tdata += "</td>";
tdata += "</tr>";

jQuery('#mytable > tbody:last').append(tdata);

任何想法,如何解决此问题?

Any idea, how to solve this ?

THX

看起来像我忘了发布一个重要的细节:

Looks like I forgot to post one important detail :

$(document).ready(function() {  
jQuery('button.delete').button();
}

该加载页面而不是为新行后的作品。

This works after loading the page but not for the new rows.

推荐答案

在准备好()函数中,要创建的jQuery的UI风格的按钮,但他们将只适用于现有的按钮。

In the ready() function, you are creating jquery-ui styled buttons, but they will only apply to currently existing buttons.

因此​​,动态地添加按钮将不会有这个适用于他们,所以你必须修改addRow作用相对于新创建的标记应用按钮()调用。

Therefore, dynamically added buttons won't have this applied to them, so you'll have to modify your addRow function to apply the button() call in relation to the newly created markup.

这样的:

var tdata = "<tr>";
tdata += "<td align=\"right\">my data</td>";
tdata += "<td align=\"left\">";
tdata += "<button class=\"delete\">delete</button>";
tdata += "</td>";
tdata += "</tr>";
var tdataElement = jQuery(tdata);
jQuery('button.delete',tdataElement).button();
jQuery('#mytable > tbody:last').append(tdataElement);

这篇关于如何添加动态jQuery的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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