2011-01-12 36 views
0
處理動態創建的下拉列表中的變化選擇項事件在PHP
function printDropDownList($lbId,$elements,$header) 
      { 
       print " 
       <tr><th align=\"right\">$lbId: </th><td> 
        <select id=\"$lbId\" style=\"width:80px;\" class=\"text ui-widget-content ui-corner-all\">"; 

        foreach($elements as $item) 
        { 
         print "<option value=\"$item[0]\">$item[1]</option>"; 
        } 

       print "</select>";       
      } 

      $db = new Database();   

      $listHeaders = $db->arrayOfChildFacetsOneLevel(206); 
      $i=0; 
      foreach($listHeaders as $listHeader) 
      { 
       $facets = array(); 
       $q=0; 
       $db->arrayOfChildFacetsRecursive($facets,$listHeader[0],$q); 
       printDropDownList("list".$i,$facets,$listHeader); 
       $i++; 
      } 

回答

1

可以使用.live()事件這個

$("#yourdropdownid").live("change", function(){ 
    var selectedVal = this.value; 
}); 

如果你有超過元素更多,你需要綁定事件,然後爲這些放置一個類名稱,並且可以使用類選擇器。

$("select.yourclassname").live("change", function(){ 
    var selectedVal - this.value; 
}); 
+0

謝謝,但是有什麼變化?它說有關這個詞的錯誤。 – 2011-01-12 09:51:50