简体   繁体   English

jQuery专注于append元素

[英]Jquery focus on append element

I want to focus an element with Jquery created by an append. 我想通过追加创建的Jquery集中元素。 My exemple : 我的例子:

$("#Collaps").append('<a id="link_tuiles_1" href="test.php">Link</a>')

$("#link_tuiles_1").focus(function(){       
alert('ok');   
});

<div id="Collaps"></div>

But it doesn't works. 但这是行不通的。 Could you help me ? 你可以帮帮我吗 ?

It will not work because you bind the function before the element is inserted on page, try it like this 这将无法正常工作,因为您在元素插入页面之前就绑定了函数,请像这样尝试

("#Collaps").append('<a id="link_tuiles_1" href="test.php">Link</a>')

$(document).on("focus","#link_tuiles_1",function(){       
 alert('ok');   
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM