find and replace problem
i working on a carousel and i would like to add an additional func开发者_JAVA技巧tionality such that, when the user clicks on an image, thumbnail if you like, that image is replaced with a large image on a div above the carousel.
I managed to get to work with just one image. so no matter, the thumbnail clicked on, the large image remains the same, which is not ideal. Also, i have named my files like this test1_thumb, test1_large. So is there like a way to find the underscore and then replace the text which in this case is (thumb) with the large?
$('.carousel ul li').click(function() {
$('.content img').replaceWith('<img src="images/test_large.jpg"/>');
});
You are very close to what you want to achieve :
$('.carousel ul li').click(function() {
$('.content img').attr('src', urcurrentPath.replace('_thumb','_large');
});
If you wrap your thumbnail image in an anchor tag with the href pointing to the larger image, you'll simplify this process greatly.
$('.carousel a').click(function() { $('.content img').replaceWith('<img src="' + this.href + '"/>'); });
精彩评论