*[id^= 选择全部,我想选择每个相同的数字
使用此代码,当您将鼠标悬停在 id="trigger*" 的任何内容上时,它会显示 id="panel*" 的所有内容,我希望触发器1 显示面板1,触发器2 显示面板2。
这可能吗?这是我的代码:
$(document).ready(function(){
hovered = false;
$('*[id^=trigger]').bind('mouseenter mouseleave', function(event) {
switch(event.type) {
case 'mouseenter':
// when user enters the div
$('*[id^=panel]').show('fast');
break;
case 'mouseleave':
// leaves
setTimeout(function(){
if(!hovered) {
$('*[id^=panel]').hide('fast');
}}, 250);
break;
}
});
$('*[id^=panel]').mouseover(function(){
hovered = true;
}).mouseout(function(){
hovered = false;
$('*[id^=trigger]').trigger("mouseout");
});
});
With this code, when you hover over anything with the id="trigger*", it shows everything with the id="panel*" I would like it, for trigger1 to show panel1, for trigger2 to show panel2.
Is that possible? This is my code:
$(document).ready(function(){
hovered = false;
$('*[id^=trigger]').bind('mouseenter mouseleave', function(event) {
switch(event.type) {
case 'mouseenter':
// when user enters the div
$('*[id^=panel]').show('fast');
break;
case 'mouseleave':
// leaves
setTimeout(function(){
if(!hovered) {
$('*[id^=panel]').hide('fast');
}}, 250);
break;
}
});
$('*[id^=panel]').mouseover(function(){
hovered = true;
}).mouseout(function(){
hovered = false;
$('*[id^=trigger]').trigger("mouseout");
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解您的要求,您希望显示距离触发的触发器最近的面板。为此,请使用
.closest()
。更改为
:
http://api.jquery.com/closest/
If I'm understanding your requirements, you would like to show the closest panel to the trigger that was triggered. Use
.closest()
for this.Change this:
To this:
http://api.jquery.com/closest/
使用正则表达式或 javascript split function 将 id 分成两部分,这样就可以获取 id,
例如在我使用的代码中
use a regular expression, or javascript split function to split the id into two parts and that way obtain the id
like for example in my code i use
从触发器对象中提取 id 并使用该 id 查找面板对象。
extract the id from the trigger object and use that id to find the panel object.