1
我在div上加載html頁面,並希望創建上一個/下一個按鈕以便於導航。什麼是實現這一目標的最佳方式?使用jquery加載上一個/下一個url
按照小提琴:https://jsfiddle.net/5vbc2vp6/6/ - 基本上我想定位下一個div href並在點擊上一個/下一個按鈕時加載它。
$(".iframe").on("click", function(e) {
e.preventDefault();
var $mylink = $(this).attr('href');
$("#myDiv").load($mylink);
});
$(".prev").on("click", function(e) {
e.preventDefault();
});
$(".next").on("click", function(e) {
e.preventDefault();
});
HTML
<a class="prev" href="#">Previous Entry</a> | <a class="next" href="#">Next Entry</a>
<p>
<div id="myDiv">
HTML loads here
</div>
</p>
<div class="entry designs">
<span class="number">1</span>
<a class="iframe" rel="design1" href="portfolio/automotive/page.html" caption="Design for Automotive company">
<img src="portfolio/automotive/thumb.jpg" alt="" border="0" width="200" height="150">
<span class="magnifier"><span class="tp-info"><span class="tp-color">Design</span> for Automotive company</span>
</span>
</a>
</div>
<div class="entry designs">
<span class="number">2</span>
<a class="iframe" rel="design2" href="portfolio/landing_page/page.html" caption="Landing page design">
<img src="portfolio/landing_page/thumb.jpg" alt="" border="0" width="200" height="150">
<span class="magnifier"><span class="tp-info"><span class="tp-color">Landing page</span> design</span>
</span>
</a>
</div>
<div class="entry print">
<span class="number">1</span>
<a class="iframe" rel="print1" href="portfolio/testobject/page.html" caption="Flyer design for TestObject">
<img src="portfolio/testobject/thumb.png" alt="" border="0" width="200" height="150">
<span class="magnifier"><span class="tp-info"><span class="tp-color">Flyer design</span> for TestObject</span>
</span>
</a>
</div>
我需要更換這片:'VAR未來= $( '#E' + currentId)的.html();'與HREF只有(而不是整個div html) – lonewulf
試試這個 - > var next = $('#e'+ currentId +'.try.iframe')。attr('href'); $('#myDiv .iframe')。attr('href',next); –
這是有效的,但是當我瀏覽項目時,它永遠不會回到第一個 - >(div id =「current」) – lonewulf