查找和替换jQuery

问题描述:

我有这段代码可以让我对提交按钮进行过渡,我正在尝试使其更加通用:

I have this code to give me a rollover on submit buttons, and I'm trying to make it more generic:

$('.rollover').hover(
            function(){ // Change the input image's source when we "roll on"
                srcPath = $(this).attr("src");
                            srcPathOver = ???????
                /*need to manipulate srcPath to change from
                img/content/go-button.gif
                into 
                img/content/go-button-over.gif
                */
                $(this).attr({ src : srcPathOver});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : srcPath});
            }
     );

真的有两件事,

我想学习如何操纵srcPath变量将文本"-over"附加到gif文件名上,从而为过渡提供新图像.有人可以建议一种方法吗?

I want to learn how manipulate the srcPath variable to append the text '-over' onto the gif filename, to give a new image for the rollover. Can anyone suggest a way to do this?

另外,有人可以告诉我是否可以完善此代码吗?我对jQuery有点陌生,想知道是否可以改进语法.

Also, can someone tell me if this code could be refined at all? I'm a bit new to jQuery and wondered if the syntax could be improved upon.

非常感谢.

$('.rollover').hover(
            function(){ // Change the input image's source when we "roll on"
                var t = $(this);
                t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1-over.$2"));
            },
            function(){ 
                var t= $(this);
                t.attr('src',t.attr('src').replace('-over',''));
            }
     );