php - How to make next/prev links by increment? -


I want the next link on my page to see the next episode. I want to do this with increment. I have this but it does not work.

  & lt; P & gt; & Lt; An id = "asdf" href = "sample-1" & gt; Next & lt; / A & gt; & Lt; Script & gt; Document.getElementById ('asdf'). AddEventListener ('click', function (e) {var n = e.target.href.split ('-') [1] * 1 + 1; if (n> 4) N = 1; e.target Href = e.target.href.split ('-') [0] + '-' + n + ".php";}, false); & Lt; / Script & gt; & Lt; Div class = "div3" & gt; & Lt; Ul & gt; & Lt; Li & gt; & Lt; A href = "sample -1.php" & gt; Anahana AP1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "sample-2.php" & gt; Anahana AP2 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "sample-3 php" & gt; Unahana EPE & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt;  

Should I determine the file name of the first page?

Use parseInt to convert the number:

  document.getElementById ('asdf'). AddEventListener ('click', function (e) {var n = parseInt (E.target.href.split ('-') [1]) + 1; if (n> 4) n = 1; e.target .href = e.target.href.split ('-') [0] + '-' + n + ".php";}, false);  

Explanation The problem with your code is that the first href after clicking sample -1.php . Which partition when producing an array ['Sample', '1.php'] When you try to change 1.php with multiplier operator * again, it returns the return of NIAN . So you should use the parseInt in this case which will properly remove the numerical part.

Demo:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -