开发者

How to handle the change selected item event of dynamically created DropDown List in PHP by jQuery

开发者 https://www.devze.com 2023-02-04 00:00 出处:网络
function printDropDownList($lbId,$elements,$header) { print \" <tr><th align=\\\"right\\\">$lbId: </th><td>
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;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消