【发布时间】:2015-01-13 11:43:10
【问题描述】:
我正在通过 jquery 在表中添加一行。每行都有一些与之关联的javascript。 当我使用 jquery 添加新行时,javascript 适用于以前的行,但不适用于新添加的行。
我需要再次加载相同的 js 吗?如果是,怎么做?
js 适用于已经 html 行,但不适用于我添加的行
<table>
<tr id="hello12">
<div class="formField" style="float:right" >
<span class="btn btn-success fileinput-button" >
<i class="glyphicon glyphicon-plus"></i>
<span>Add Attachments...</span>
<input id="fileupload" type="file" name="attachment" multiple>
</span>
</div>
</tr>
</tr>
<tr class="row">
<td>
<button type="button" id="override_button">
<b>+</b>
</button>
</td>
</tr>
</table>
$('#fileupload').fileupload({
url: '/attachments/create',
dataType: 'json',
done: function (e, data) {
alert("done");
},
});
$('#override_button').click(function(){
alert("hello")
$('#hello12').after('\ <tr id="hello12">
<div class="formField" style="float:right" >
<span class="btn btn-success fileinput-button" >
<i class="glyphicon glyphicon-plus"></i>
<span>Add Attachments...</span>
<input id="fileupload" type="file" name="attachment" multiple>
</span>
</div>
</tr>')
});
【问题讨论】:
-
是的。如果没有看到您的代码,我们无法确定如何告诉您。您要么需要重新附加事件,要么使用委托的事件处理程序。
-
只告诉我在表格中添加一行后如何再次加载js?这如何与代码链接..
-
只需向我们展示您的代码,我们会提供帮助。除非您在此处发布一些代码只是为了让您知道,否则您的问题更有可能被关闭。
-
询问有关特定代码的问题没有发布相关代码是很愚蠢的,不是吗?也许是,也许不是,谁知道???
-
我们的意思是您的 JS 代码,它在第一个实例中附加了您的事件处理程序。
标签: javascript jquery html ruby-on-rails