附加按钮的onclick不火的Jquery [英] appended button onclick don't fire Jquery
本文介绍了附加按钮的onclick不火的Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮,追加2文本字段和在表TD的一个按钮,然而,问题是,在所附按钮的onclick功能不火。任何人看到这个问题?
code:
<脚本>
$(文件)。就绪(函数(){
$(#中)。点击(函数(){
$(。NO_BORDER)追加(< BR /><标签>共同作者的电子邮件:LT; /标签><输入类型=文本名称='AUTHOR_EMAIL/><标签&gt ;合着者等级:LT; /标签><输入类型=文本名称='author_level/><输入ID ='保存'类型='button'name ='保存'值='添加' />中);
});
});
< / SCRIPT>
< PHP
而($行= mysql_fetch_assoc($ co_authors)){
回声< TR>
< TD> {$行['AUTHOR_EMAIL']}< / TD>
< TD> {$行['coauthor_level']}< / TD>中;
?>< TD><按钮类='删除'ID =删除NAME =删除邮件=< PHP的echo $行['AUTHOR_EMAIL']>?
纸=< PHP的echo $行['paper_id']>>删除< /按钮>< / TD>
< / TR>&LT ;?
?>< TD合并单元格=3级=NO_BORDER><按钮类=添加NAME =添加>< /按钮>
<标签ID =添加级=cursor_pointer>添加更多的合着者< /标签>< / TD>&LT ;?
}
?>
解决方案
您将需要使用jQuery的。对()
功能来访问创建的元素在DOM后加载。
更具体的信息可以在jQuery的手册在这里找到:
http://api.jquery.com/on/
的$(document)。在(点击,#将功能(){
警报(AAAAAAAAAAA);
});
在jQuery和LT; 1.7,这是pviously使用像这样$ P $:
$(#将).live(点击,功能(五){});
I am having a button which appends 2 textfields and a button in a table td, however the problem is that the onclick function of the appended button don't fire. anyone sees the problem? code:
<script>
$(document).ready(function(){
$("#add").click(function() {
$(".no_border").append("<br /><label>Co-author email:</label><input type='text' name='author_email'/><label>Co-author Level:</label><input type='text' name='author_level'/><input id='save' type='button'name='save' value='Add'/>");
});
});
</script>
<?php
while($row = mysql_fetch_assoc($co_authors)) {
echo "<tr>
<td>{$row['author_email']}</td>
<td>{$row['coauthor_level']}</td>";
?><td><button class='remove' id='remove' name='remove' email="<?php echo $row['author_email'] ?>"
paper="<?php echo $row['paper_id'] ?>">Remove</button></td>
</tr><?
?><td colspan="3" class="no_border"><button class="add" name="add"></button>
<label id="add" class="cursor_pointer"> Add more co-authors</label></td><?
}
?>
解决方案
You will need to use the jQuery .on()
functionality to access elements created after the DOM has loaded.
More specific info can be found in the jQuery manual here: http://api.jquery.com/on/
$( document ).on( "click", "#add", function() {
alert("aaaaaaaaaaa");
} );
In jQuery < 1.7 , this was previously used like so:
$( "#add" ).live( "click", function( e ) {} );
这篇关于附加按钮的onclick不火的Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文