使用带有'on'函数的动态附加元素,而不使用'events'

时间:2014-12-14 02:49:48

标签: javascript jquery

在使用jquery加载函数从另一个文件动态追加后,我无法访问隐藏的警报。我还附上了#addMovie'动态按钮,并了解到我可以通过' on'来触发它。功能,但我不能在'#alertSuccess'上做同样的事情。因为它没有像点击这样的事件。与'一起使用'功能,它是隐藏的,它会自动显示。 1)如何在没有'事件的情况下更新此DOM?但是使用''功能? 要么 2)我可以触发并显示这个元素而不需要打开'功能? 要么 3)我可以在追加后更新所有DOM,并像其他现有元素一样使用.click函数,所以我不再需要('点击' ...)函数了吗?

// Both '#addMovie' and '#alertSuccess' appended dynamically 
// into '#searchMovieDiv' element.

$('#searchMovieDiv').on('click', '#addMovie', function(e){ // can trigger this with 'on'

      ....
      ....
$('#alertSuccess').show(); // can't trigger this with 'on' cause
                          // it has no events, will be visible without condition


      ....
      ....
}

// Appended alert
<div class="alert alert-success" id="alertSuccess">
    <strong>Movie added</strong>
</div>

0 个答案:

没有答案