鼠标输入 鼠标离开 帮助获取大量信息

发布于 2024-12-22 12:42:19 字数 1590 浏览 3 评论 0原文

我也想为每个州和每个城市设置一个链接。 当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┾廆蒐ゝ 2024-12-29 12:42:19

查找城市时需要添加上下文,例如 $('.citys', this).toggle();
这将搜索位于 this 内部的 .citys 元素,在本例中是悬停的 .ui-state-default 元素。

        $('.ui-state-default').mouseenter(function(e) {
            $('.citys', this).toggle(); // added this 
        }).mouseleave(function(e) {
            $('.citys', this).toggle(); // added this 
        });

了解如何使用上下文参数 http://api.jquery.com/jquery/#jQuery1


或者,您可以使用 .find()

$(this).find('.citys').toggle();

You need to add context when finding the cities, like this $('.citys', this).toggle();
This will search for .citys elements located inside this which in this case is the hovered .ui-state-default element.

        $('.ui-state-default').mouseenter(function(e) {
            $('.citys', this).toggle(); // added this 
        }).mouseleave(function(e) {
            $('.citys', this).toggle(); // added this 
        });

See how to use the context parameter at http://api.jquery.com/jquery/#jQuery1


Alternatively you can use .find()

$(this).find('.citys').toggle();
时光磨忆 2024-12-29 12:42:19

您不需要为此使用 JavaScript。查找“css:hover”...这都可以由样式表处理。

You don't need javascript for this. Look up "css: hover"... this can all be handled by the stylesheets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文