鼠标输入 鼠标离开 帮助获取大量信息
我也想为每个州和每个城市设置一个链接。 当 li 州悬停时,我只想显示该州的城市.... 但我只知道一点 jquery 代码,而且我对选择器的理解并不完美, 我不确定如何使用 .each jquery 函数....请帮助!!!! PHP代码:
<?
$everything = array(
'states'=>array(
'Alabama'=>array('Birmingham,Montgomery,Mobile,Huntsville,Tuscaloosa'),
'Alaska'=>array('Anchorage,Juneau,Fairbanks,Sitka,Ketchikan'),
'Arizona'=>array('Phoenix,Tuscon,Mesa,Glendale,Scottsdale'),
'Arkansas'=>array('Little Rock,Fort Smith,North Little Rock,Fayetteville,Jonesboro'),
)
);
$id = md5(0);
$controll = 0;
$here = md5('states');
echo "<div id=\"9090\"><ol id=\"selectable\">";
foreach($everything['states'] as $state=>$city){
$citys = explode(',',$city[0]);
echo "<li class=\"ui-state-default\"><a class=\"contr\" href=\"#\">$state</a> <div class=\"citys\">";
foreach($citys as $key=>$x){
echo "<a href=\"#\">$x</a><br>";
}
"</div></li>";
}
echo "</ol></div>";
?>
jquery:
<script>
$(function() {
$( "#selectable" ).selectable();
});
$('.ui-state-default').mouseenter(function(e) {
// here when i hover over this state all citys show i just want the cities for this sate
$('.citys').toggle();
}).mouseleave(function(e) {
// here when i leave this state li all theese citites should leave
$('.citys').toggle();
});;
</script>
i would like too set a link for every state ,and every city.
when the state li is hovered over i only want that this states cities to show ....
but i kno only a little jquery code and im not perfect with understanding the selectors,
im not to sure on how to use the .each jquery function.... please help!!!!
php code:
<?
$everything = array(
'states'=>array(
'Alabama'=>array('Birmingham,Montgomery,Mobile,Huntsville,Tuscaloosa'),
'Alaska'=>array('Anchorage,Juneau,Fairbanks,Sitka,Ketchikan'),
'Arizona'=>array('Phoenix,Tuscon,Mesa,Glendale,Scottsdale'),
'Arkansas'=>array('Little Rock,Fort Smith,North Little Rock,Fayetteville,Jonesboro'),
)
);
$id = md5(0);
$controll = 0;
$here = md5('states');
echo "<div id=\"9090\"><ol id=\"selectable\">";
foreach($everything['states'] as $state=>$city){
$citys = explode(',',$city[0]);
echo "<li class=\"ui-state-default\"><a class=\"contr\" href=\"#\">$state</a> <div class=\"citys\">";
foreach($citys as $key=>$x){
echo "<a href=\"#\">$x</a><br>";
}
"</div></li>";
}
echo "</ol></div>";
?>
jquery :
<script>
$(function() {
$( "#selectable" ).selectable();
});
$('.ui-state-default').mouseenter(function(e) {
// here when i hover over this state all citys show i just want the cities for this sate
$('.citys').toggle();
}).mouseleave(function(e) {
// here when i leave this state li all theese citites should leave
$('.citys').toggle();
});;
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查找城市时需要添加上下文,例如
$('.citys', this).toggle();
这将搜索位于
this
内部的.citys
元素,在本例中是悬停的.ui-state-default
元素。了解如何使用上下文参数 http://api.jquery.com/jquery/#jQuery1
或者,您可以使用
.find()
You need to add context when finding the cities, like this
$('.citys', this).toggle();
This will search for
.citys
elements located insidethis
which in this case is the hovered.ui-state-default
element.See how to use the context parameter at http://api.jquery.com/jquery/#jQuery1
Alternatively you can use
.find()
您不需要为此使用 JavaScript。查找“css:hover”...这都可以由样式表处理。
You don't need javascript for this. Look up "css: hover"... this can all be handled by the stylesheets.