图像选项卡 jquery onclick 和 mouseout 函数
我只处理图像选项卡,而不是
选项卡,
有图像 a.png
和 ah.png
, -h
代表悬停图像。 我们有 3 张并排的图像作为选项卡。 但我使用mouseout
功能,点击功能消失,即活动选项卡的悬停被删除。
下面是 html 代码
<div class="container">
<div class="TabMenu">
<span><img src="images/a.png"></span>
<span><img src="images/b.png"></span>
<span><img src="images/c.png"></span>
</div>
</div>
下面是 jQuery 代码
$(".container .TabMenu span").mouseover(function(){
var myRegExp = /-h./;
var myRegExp2 = /-h-h./;
var str1 = $('img', this).attr('src');
var match = str1.search(myRegExp);
var match2 = str1.search(myRegExp2);
if(match == -1 ){
var newSrc = $('img', this).attr('src').replace(".", "-h.");
$('img', this).attr("src", newSrc);
}
else if(match2 == -1){
var newSrc = $('img', this).attr('src').replace("-h-h.","-h.");
$('img', this).attr("src", newSrc);
}
});
$(".container .TabMenu span").mouseout(function(){
var myRegExp = /-h./;
var myRegExp2 = /-h-h./;
var str1 = $('img', this).attr('src');
var match = str1.search(myRegExp);
var match2 = str1.search(myRegExp2);
if(match != -1){
var newSrc = $('img', this).attr('src').replace("-h.", ".");
$('img', this).attr("src", newSrc);
}
else if(match2 != -1){
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
}
});
$(".container .TabMenu span").click(function(){
var myRegExp2 = /-h./;
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
});
$(".container .TabMenu span").click(function(){
var myRegExp2 = /-h./;
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
});
});
当我将鼠标悬停在单击的图像上然后移出单击的图像时,活动舞台即图像的 -h
被移出。 我们如何实现这个,悬停,活动,我使用正则表达式来避免鼠标悬停在单击的图像上。
I am working on Image Tabs only not the <ul><li>
tabs,
There are images a.png
and a-h.png
, -h
represents the hover image.
We have 3 images side by side acting as tabs.
But i user mouseout
function, the click function goes out ie the hovering of the active tabs is removed.
below is the html code
<div class="container">
<div class="TabMenu">
<span><img src="images/a.png"></span>
<span><img src="images/b.png"></span>
<span><img src="images/c.png"></span>
</div>
</div>
And below is the jQuery Code
$(".container .TabMenu span").mouseover(function(){
var myRegExp = /-h./;
var myRegExp2 = /-h-h./;
var str1 = $('img', this).attr('src');
var match = str1.search(myRegExp);
var match2 = str1.search(myRegExp2);
if(match == -1 ){
var newSrc = $('img', this).attr('src').replace(".", "-h.");
$('img', this).attr("src", newSrc);
}
else if(match2 == -1){
var newSrc = $('img', this).attr('src').replace("-h-h.","-h.");
$('img', this).attr("src", newSrc);
}
});
$(".container .TabMenu span").mouseout(function(){
var myRegExp = /-h./;
var myRegExp2 = /-h-h./;
var str1 = $('img', this).attr('src');
var match = str1.search(myRegExp);
var match2 = str1.search(myRegExp2);
if(match != -1){
var newSrc = $('img', this).attr('src').replace("-h.", ".");
$('img', this).attr("src", newSrc);
}
else if(match2 != -1){
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
}
});
$(".container .TabMenu span").click(function(){
var myRegExp2 = /-h./;
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
});
$(".container .TabMenu span").click(function(){
var myRegExp2 = /-h./;
var newSrc = $('img', this).attr('src').replace("-h-h.", "-h.");
$('img', this).attr("src", newSrc);
});
});
When I hover on clicked image then move out of the clicked image, the active stage stage ie -h
of the image is moved out..
How can we implement this, hover, active and I used regex expressions to avoid the hovering mouseout on clicked image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白你想要什么,但尝试用这种方式而不是正则表达式:
和 jQuery:
那么,它是正确的吗? :
I don't understand very well what do you want, but try by this way instead of regex :
And jQuery :
So, is it correct ? :