javascript - Increment number within string. -


i have simple image viewer on page loads thumbnails underneath. when click thumbnail, swaps thumbnail link main image removing thumbnail folder url so:

$('#scroller img').on("click",function(){ $('#main-img').attr('src',$(this).attr('src').replace('t/', '')); }); 

but want people able click on left , right arrows advance or go one.

here code right arrow:

$('#rar').on("click",function(){   /*$('#main-img').attr('src',$(this).attr('src').replace(/(\d+)/, function(){return arguments[1]*1+1} ));*/  $('#main-img').attr('src',$(this).attr('src').replace(/\d+/, function(val) { return parseint(val)+1}));  }); 

i think syntax may wrong. isn't working anyway. neither did failed attempt can see commented out.

but i'd filecount in image directory , increment 1 in blah/1.jpg until reaches filecount or decrement until reaches 0 left arrow.

my filenames 0 padded 001.jpg, 002.jpg, thought complicate things further did away padding, unless has simple method too.

simplicity key here. didn't want have jump through hoops increase or decrease damned number.

any appreciated , time in advance ;-)

try val should second argument in anonymous function:

$('#main-img').attr('src',$(this).attr('src').replace(/\d+/, function(_, val) { return (parseint(val)+1);}));  

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -