简体   繁体   中英

Javascript innerHTML with form

I am trying to move between pages, but when I try to go to the next page it does not work as expected. When I click it the first time the result is 01 instead of 1, and the second time it becomes 011 instead of 2. What am I doing wrong?

HTML :

<p id='page'>0</p>
<div id='pics'>
    <a href='<?=URL;?>index.php?p=gallery&image=<?=$pic['album_pic_id'];?>'>
        <img class='<?php if($pic['album_pic_id'] == $image) 
            { echo "selected_pic"; } ?>' width='90px' height='60px'
            src='<?=URL;?>images/albums/<?=$pic['album_pic_photo'];?>' />
     </a>
     <a onclick='getElementById("page").value = getElementById("page").value+1;'>
         Pievienot
     </a>
 </div>

Javascript :

window.onload = function() {
    var page = 0;
};

Use innerHTML and parse its content to an integer with parseInt :

<a onclick='getElementById("page").innerHTML = parseInt(getElementById("page").innerHTML) + 1;'>Pievienot</a>

value only works with form elements such as input .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM