查找和替换jQuery [英] Find & replace jquery
本文介绍了查找和替换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',''));
}
);
这篇关于查找和替换jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文