Find & replace jquery

后端 未结 3 1884
感动是毒
感动是毒 2020-12-17 02:01

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          


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 02:39

    You should be able to use a regex replace to modify your source path. Like this:

    srcPathOver = srcPath.replace(/([^.]*)\.(.*)/, "$1-over.$2");
    

    More on JavaScript regexes here

    As far as how you're doing it, I'd make sure that you define your srcPath variable like this

    var srcPath;
    $('.rollover').hover(...
    

    The code you have above makes it look like srcPath is a global variable, which is not what you want.

提交回复
热议问题