最简单的方法
当点击按钮时,隐藏或显示 p 元素:
代码如下 |
复制代码 |
$("button").live("click",function(){
$("p").slideToggle();
}); |
jQuery在动态生成HTML元素后,如果该元素集合中有鼠标点击CLICK事件。
这时点击无响应,需要用到.live()方法使生成的动态元素依然保持页面装载后的效果,使鼠标点击事件生效。
代码如下 |
复制代码 |
jQuery(document).ready(function(){
var contentTR=$('.info tr:eq(0)').html();
var e=0;
$('.addrow').click(function(){
e=e+1;
$(".info .addrow").parent().parent().before(' |
' + contentTR + '
');
$(".info tr:eq("+e+")").find("input:eq(0)").attr("name","a"+e);
$(".info tr:eq("+e+")").find("input:eq(1)").attr("name","b"+e);
$(".info tr:eq("+e+")").find("select:eq(0)").attr("name","c"+e);
$(".info tr:eq("+e+")").find("input:eq(2)").attr("name","d"+e);
$(".info tr:eq("+e+")").find("input:eq(3)").attr("name","f"+e);
});
$('.del').live('click',function(){
$(this).parent().parent().remove();
});
});