当前位置: 动力学知识库 > 问答 > 编程问答 >

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;
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: