动态插入的DOM元素不可使用$ .click() [英] Dynamically Inserted DOM Elements are not Clickable using $.click()
问题描述
我使用jQuery来获取表单元素的值,并将其放在列表项标签中。最大值为三个列表项(这些将成为图片的标签)。
问题是,我希望人们能够删除任何错误的标签他们已通过点击进入,但项目(使用jQuery动态插入到< ul>标记中)不可点击使用:
$('li.tag')。click(function(){/ * Do stuff Here * /});
它甚至不会触发警报。
有没有人能够解决这个问题?
实时方法:
http://api.jquery.com/live/ p>
也许你可以这样做
$('li.tag' ).live('click',function(){/ * Do stuff here * /});
I'm using jQuery to take the value of a form element and place it inside a list item tag. There is a maximum value of three list items (these are to become tags for an image).
The problem is that i want people to be able to remove any erroneous tags they've entered by clicking on them, but the items (which are dynamically inserted into a <ul> tag using jQuery) are not clickable using:
$('li.tag').click(function(){ /* Do stuff here */ });
it won't even fire off an alert.
Does anyone have any ideas how i can work around this problem?
I think you're looking for the live method: http://api.jquery.com/live/
Perhaps you could do something like
$('li.tag').live('click', function() { /* Do stuff here */ });
这篇关于动态插入的DOM元素不可使用$ .click()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!