Drop down box binding event
*
When the normal drop-down box binds data , You need to input data one by one . however , Drop down box is not required to bind data , It only needs to bind the value of the database to succeed , So how is the binding successful ? Now let's learn about it :
(1)
When binding a drop-down box , First of all, it must have its style , When binding a drop-down box , It must also be placed in the From In the form , Only in this way can we get its value , adopt From Forms are also easier to get data . Here's an example From The style of .
<div class="col-12 mt-2">
<form class="form-inline form-row">
<label class="col-form-label mr-3" for="searchBillID"> Pharmaceutical companies </label>
<select id="searchComID" class="form-control form-control-sm mr-4
col-sm-1 col-md-1"></select>
</form>
</div>
(2) After binding the data, you can write it JS The data is up , A drop-down box is used to bind data , Its writing is not complicated . Here is an original way to write it , In this way, the amount of his code will be greatly increased . therefore , In fact, we can package his code for use , Then the amount of code will be far less than the method written below , And even if there are more drop-down box binding data , We just need to call it , There is no need to write one by one .
$(document).ready(function () {
$.get("SelectAcademe", function (data) {
$("#sltAcademe").append('<option value="' + data[0].id + '">' + data[0].text +
'</option>');
for (var i = 0; i < data.length; i++) {
$("#sltAcademe").append('<option value="' + data[i].id + '">' + data[i].text
+ '</option>');
}
$.each(data, function (i) {
$("#sltAcademe").append('<option value="' + data[i].id + '">' + data[i].text +
'</option>');
});
(3) Method of encapsulating binding drop-down box :
* After encapsulation, you need to write the method in the controller : Note the following when writing the controller method Select new Don't write it wrong , If you write it wrong, it won't get the data ,
* The last step is to bind the data , use From To submit the data ,CreateSelect It's followed by ID And methods .
Technology