javascript - Load Failed image into HTML -


<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">    <head>    <title></title>    <script type="text/javascript">      var = 1;      window.onunload = function() {        debugger;      }        function para() {        = + 1;        var source = document.getelementbyid('p').src;        document.getelementbyid('p').src = source.replace(i - 1, i);      }    </script>  </head>    <body>    <div><img alt="image" id="p" src="images/para/p-1.jpg"></div>    <div><img id="q" src="images/q/p-1-q-1.jpg" </div>      <div><img id="a" src="images/a/p-1-q-1-a-1.png"></div> <input id="button1" type="button" value="next parigraph" onclick="para()" /> <input id="button2" type="button" value="next question" /> <input id="button3" type="button" value="next answer" /> </body>    </html>

actually want create html page can load images. code returns load failed p-3.jpg. not understand why happening.first loads p-1.jpg after p-2.jpg , after clicking second time not load , gives load failed.please

if understand correctly think problem here replace() function , js replace() function replace first parameter second parameter . when taking src of img object

var source = document.getelementbyid('p').src; 

it taking whole src of object , according here have image path correct ? images/para/p-1.jpg , when replacing src using replace function , in next retain value of i = + 1; , think can try

source.replace("images/para/p-"+i - 1+".jpg", "images/para/p-"+i+".jpg"); 

to suggest can please follow convection of variable declaration , here used var source there reserved keyword source in javascript. may conflict reserved keyword , please let me know done correctly . if not feel free ask me again


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -