【问题标题】:mouse enter mouse leave help for a big array of info鼠标输入 鼠标离开 帮助获取大量信息
【发布时间】:2012-01-25 17:03:10
【问题描述】:

我也想为每个州和每个城市设置一个链接。 当国家 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>

【问题讨论】:

    标签: jquery mouseover mouseenter mouseleave


    【解决方案1】:

    您需要在查找城市时添加上下文,例如 $('.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();
    

    【讨论】:

      【解决方案2】:

      您不需要 javascript。查找“css: hover”...这都可以由样式表处理。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-21
        • 2014-02-21
        • 1970-01-01
        相关资源
        最近更新 更多