[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
下拉框绑定事件
*
平常的下拉框绑定数据时,需要一个一个的数据输入。但是,下拉框绑定数据时不需要,它只需绑定数据库的值就可以绑定成功,那么是怎么绑定成功的呢?下面我们就来学习一下:
(1)
在绑定一个下拉框的时候,首先必须要有其样式,绑定下拉框时,还必须放在From表单里面,这样才能获取到它的值,通过From表单获取数据也更加的容易。下面就是一个放在From的样式。
<div class="col-12 mt-2">
<form class="form-inline form-row">
<label class="col-form-label mr-3" for="searchBillID">医药公司</label>
<select id="searchComID" class="form-control form-control-sm mr-4
col-sm-1 col-md-1"></select>
</form>
</div>
(2)绑定完数据后就可以写它的JS数据了,一个下拉框绑定数据,它的写法不算复杂。下面是一个它的原始的写法,这样写他的代码量将会远远增加。所以,其实我们可以把他的代码封装起来使用,那么其代码量将会远远少于下面写的那种方法,而且就算有再多的下拉框绑定数据,我们就只需要调用它就好了,不需要一个个的写。
$(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)封装的绑定下拉框的方法:
* 封装完后还需要在控制器写方法:在控制器写方法的时候要注意下面Select new的值一定不要写错了,写错了它会获取不了数据,
* 最后一步就是绑定数据了,用From来提交数据,CreateSelect后面加的是ID和方法。