How to handle the change selected item event of dynamically created DropDown List in PHP by jQuery
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++;
}
You can use .live()
event for this
$("#yourdropdownid").live("change", function(){
var selectedVal = this.value;
});
If you have more than element for which you need to bind the event then put a class name for those and you can use the class selector.
$("select.yourclassname").live("change", function(){
var selectedVal - this.value;
});
精彩评论