2011-12-21 69 views
1

我也想爲每個州和每個城市設置一個鏈接。 當國家李是徘徊我只希望這個州的城市顯示.... 但我知道只有一個小jQuery代碼和IM不理想的選擇器, 即時通訊不知道如何使用。每個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> 

回答

1

您需要添加上下文尋找城市的時候,像這樣$('.citys', this).toggle();
這將搜索位於內this在這種情況下是懸停.ui-state-default元素.citys元素。

 $('.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(); 
0

你不需要的JavaScript這一點。查找「css:hover」......這一切都可以通過樣式表來處理。