jquery Ajax 多级联动插件
#### js $('select.ajax-linkage').on('change', function () { var $this = $(this), $next_node = $($this.data('nextnode')), $selectedOpt = $this.find('option:selected'), url = $this.data('url'), key = $this.data('key') || 'id', valueKey = $this.data('valuekey') || 'name'; if ($selectedOpt.length < 1) { $selectedOpt = $('<option value="">请选择</option>') } var ajax_data = $selectedOpt.data(); ajax_data['ajax_value'] = $this.val(); $.ajax({ url: url, type: 'get', data: ajax_data, dataType: 'json', success: function (data) { console.log('select.ajax-linkage'); var options_str = '<option value="">请选择</option>'; if (data.data) { var displayKeyStr = $this.data('displaykeys') || '', displayKeys = displayKeyStr.split(','); $.each(data.data, function (i, obj) { var value = obj[key] || ''; options_str += '<option value="' + value + '" '; var attrs = displayKeys.map(function (k) { return "data-" + k + '="' + obj[k] + '"'; }); options_str += attrs.join(' '); options_str += '>' + obj[valueKey] + '</option>'; }); $next_node.html(options_str); $next_node.trigger("change"); } } }); });
<select class="form-control input-inline input-small ajax-linkage" data-url="" data-nextnode="#base_l2" data-key="id" data-valuekey="name" data-displaykeys='no,size' id="base_l1" name="base_l1"> <option value="">请选择</option>... </select> <select class="form-control input-inline input-small ajax-linkage" data-url="" data-nextnode="#base_l3" data-key="id" data-valuekey="name" data-displaykeys='no' id="base_l2" name="base_l2"> <option value="">请选择</option> </select> <select class="form-control input-inline input-small" id="base_l3" name="base_l3"> <option value="">请选择</option> </select>
相关推荐
TONIYH 2020-07-22
83510998 2020-07-18
wcqwcq 2020-06-26
delmarks 2020-06-14
ppsurcao 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03