开发者

Img location/src replacement with a php or javascript?

开发者 https://www.devze.com 2023-02-09 19:41 出处:网络
Hi all I have a question as i just seen a script which could possibly help but am limited in my understanding of javascript or even php.

Hi all I have a question as i just seen a script which could possibly help but am limited in my understanding of javascript or even php.

the pieces of coded i just seen:

$(function() {
    $("img")
        .hover(function() { 
            var src = $(this).attr("src").match(/[^\.]+/) + "over.gif";
            $(this).attr("src", src);
        })
});

$('img.swap').hover(function () {
    this.src = '/images/signup_big_hover.png';
}, function () {
    this.src = '/images/signup_big.png';
});

basically I have a very large site and have images all over the place in various folders, now I want to move them all into one folder in root, with开发者_StackOverflowout having to change the 300+ pages.... Is it possible to change the image path from what is stated in the src to an alternative with such a script? Would appreciated any help.

Thanks in advance


You could manipulate the src of each img elements in your page with jQuery. However:

a/ The function that you show is applied to the images on mouse over, that;'s not what you want.

b/ I'd recommend to do that with a search and replace on all your site's pages or DB entries instead of doing it with JavaScript dynamically. I think the use of a PHP variable to set your image path is the best and most flexible solution.


You can easily achieve this with Dreamweaver using the integrated search & replace feature.

The feature gives you the option of searching through directories and modifying files based off of the parameters supplied.

Ex.

Search For: "images/lol.jpg"

Replace With: "new/lol.jpg"

If you do not have Dreamweaver, I recommend getting it because it's a great tool to have. :)


I hate to say but I guess the long dreaded way is the only solution, replacing each and every src tag to the new location. Thanks all for the help and ideas been great and have actually learnt something which makes this an ever better experience. Thanks very much! So my solution as much as I wanted to avoid it even thou it is in my best interest for now and future will be to replace all with variables and simply create a location file directing all src attribs to a single folder, going to be allot of work i didn't want....... Maybe next time I think of the structure before going ahead and blasting out 300 pages with notepad lol

Thanks again


Maybe you could use something like this:

http://www.jsfiddle.net/SfJP9/1/

Is this what you were going for?

Like this you can get the src of the image

http://www.jsfiddle.net/UMQ5W/2/

0

精彩评论

暂无评论...
验证码 换一张
取 消