0

当事件单击 button1 时,我让 jQuery 代码添加 HTML elemnet button2 ,并在单击 button2 时创建另一个以将另一个 HTML 元素添加到 DIV 第一个运行但第二个不运行。如何解决这个问题呢 ?

问题示例

var button2='<input type="button" vale="add" id="idbutton2" >';
$('#idbutton1').click(function(){
  $('#divid1').html(button2);
});

$('#idbutton2').click(function(){
  $('#divid2').html("text");
});

button2 添加到 DIV,我想在单击 button2 时运行 jQuery。

4

2 回答 2

0

将其更改为:

$('#divid1').on('click', '#idbutton2', function(){
    $('#divid2').html("text");
});
于 2012-09-10T03:32:26.147 回答
0

改为.on委托事件处理程序。

$(document).on('click', '#idbutton2', function(){
  $('#divid2').html("text");
});

或者你可以直接将它绑定在 button2 上。

var button2= $('<input type="button" vale="add" id="idbutton2" >').click(function(){
  $('#divid2').html("text");
});

$('#idbutton1').click(function(){
    $('#divid1').html(button2.html());
});
于 2012-09-10T03:33:09.057 回答