简体   繁体   中英

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;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM