我已经完成了一些搜索并找不到此答案,所以我想我会在这里问我的第一个问题。在div上使用JavaScript函数单击已使用获取的div获取
基本上,在一个div的点击,我正在获取一些HTML使用获取和追加到一个div的底部。获取的html包含最初点击过的同一个div。我需要点击才能运行与原始div相同的功能。这是很难解释,并通过使用JScrollPane的工作变得更为复杂
因此,这是相关的JavaScript:
$(document).ready(function ($) {
$(document).on('click', 'div#append-tweets', function() {
//The url is altered to collect the next page of tweets in my example, but this will do
var currentURL = document.URL;
currentURL = currentURL + " #content-area > *";
//gets data from the url
$.get(currentURL, function (data) {
//finds the tweets on the page and returns them as HTML
html = $(data).find('#content-area').html();
//appends the html to the div - uses api as this is the JScrollPane
api.getContentPane().append(html);
}, 'html');
//reload the scrollbar
api.reinitialise();
//makes div button disappear after it is clicked
document.getElementById('append-tweets').style.display = "none";
});
});
这是相关的HTML:
<div id="content-area">
//other stuff
<div id="append-tweets">Load More Tweets</div>
</div>
目前,该功能运行在第一次点击,并且一切正常。按钮的div消失(这是好事),新的内容被加载,包括新的按钮div,但这是不可点击的,即使它具有相同的ID。预先感谢任何帮助,我对JS和JQuery相当陌生。
“即使它具有相同的ID”也许这是你的问题,然后给新项目的新的ID,并适当地更改代码 – varnie 2013-03-05 17:10:15
没错,就是这样,?。感谢。 – user2136709 2013-03-05 17:27:22