单击即时创建的链接 [英] click on link that created on the fly

查看:68
本文介绍了单击即时创建的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题的目的只是为了解决问题



i有这个HTML

the purpose of this question is just to figure something out

i have this html

<div id='div1'>
<input id='btn1' type='button' value='click here'/>
</div>



和此jquery


and this jquery

$('#btn1').click(function(){
$('#div1').append($("<a id='link1' target='_blank' href='http://www.google.com'>google </a>"));
});
$('#btn1').click();
$('#link1').click();



-以上示例的目的是自动打开谷歌链接,以测试我是否可以点击动态创建的元素。

上述代码不能用作预期



如果我更换


-the purpose of above example is to open google link automatically to test if i can click elements that created on the fly or not.
the above code not worked as expected
but
if i replace

$('#link1').click();



with


with

document.getElementById('link1').click();



它有效。



所以我需要解释,谢谢。


it works .

So i need explanation , thanks.

推荐答案

' #btn1 ')。click( function (){
('#btn1').click(function(){


' #div1')。append(
('#div1').append(


< a id ='link1'target ='_ blank'href ='http://www.google.com'> google< / a>));
});
("<a id='link1' target='_blank' href='http://www.google.com'>google </a>")); });


这篇关于单击即时创建的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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