私はそれをクリックすると、リスト内のリンクからデータ属性を取得しようとしています。
$(document).on("click", "ul.pagination li a", function(e)
{
e.preventDefault();
var page = $(this).attr("page");
var article_id = getUrlParameter("aid");
alert(page);
$(".comments").load("page", {"type":"reload", "article_id":article_id, "page":page}, function() {
$(".comments").scrollMinimal();
$(".comments").highlight();
});
});
リストは次のようになります。
<div class="fnone">
<ul class="pagination">
<li><a data-page="2" href="testpage=2#comments">2</a></li>
私の問題は、「ページ」は常に undefined
。私はここでどこが間違っているのかは完全にはわかりません。
回答:
回答№1は1- つかいます
.attr("data-page")
これは属性の名前なので
$(document).on("click", "ul.pagination li a", function(e){
e.preventDefault();
var page = $(this).attr("data-page");
alert(page)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
A list would look like this:
<div class="fnone">
<ul class="pagination">
<li><a data-page="2" href="testpage=2#comments">2</a></li>
</ul>
</div>