The following small series will provide you with a method for jQuery to add events to the dynamically generated select element. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at the small editor. You need to dynamically generate the select element when you click the button in the project. To prevent data from being retrieved from the server every time you click the button (because the data is the same), you can write code like this.
1. First define global js Variables
Var strVoucherGroupSelect = "";
2. Write the code for obtaining server data in js.
Function genVoucherGroupSelect (rowID) {return $ (strVoucherGroupSelect ). attr ("id", "sl _" + rowid0000.parent().html (); // return the complete html in the drop-down box after adding the ID} function getVoucherGroupData () {$. ajax ({type: "Post", url: "/BillWeb/OrgVoucher/GetVoucherGroup", dataType: "json", data: "", cache: true, success: function (res) {var str = $ (""); Var option =" "; for (var j = 0; j <res. length; j ++) {option + =""+ Res [j]. Text +"";}Strvouchergroupselect = certificate (str;.html(option;.parent().html ();}});}
3. Compile the initialization code on the page.
$().ready(function(){ getVoucherGroupData(); });
4. When you need to dynamically Add a select statement, you can write it like this.
$("#pID").append(genVoucherGroupSelect(rowID) );
5. Add a click event to the select statement.
$ ("# Sl_0" + rowID). bind ("change", function () {alert ("You clicked the drop-down box ");})
The above jQuery Method for adding events to the dynamically generated select element is all the content shared by the editor. I hope to give you a reference and support for PHP.
For more information about how jQuery adds events to dynamically generated select elements, see PHP!