Uncaught TypeError: layui.form is not a function的错误
我现在使用的就是X-admin1.1版本的后台模板,在实现了三级联动的情况下想套上去结果发现会报上面的错误等等
代码语言:javascript复制在html中select标签需要加上 lay-filter="" 如下代码中所示,后面才能选中到这个select,form.render();是为了渲染这个改变的下拉框
<select lay-filter="demo1" name="hostel_id1" id="hostel_id1" style="width:150px;">
<option>请选择</option>
{volist name="hostel_list" id="hostel"}
<option value="{$hostel['name']}">{$hostel['name']}</option>
{/volist}
</select>
<script type="text/javascript">
layui.use(['form', 'jquery'],function(){
var $ = layui.jquery;
var form = layui.form();
form.on('select(test1)', function(data){
var province_id = data.value;
$.get("{:url('index/Admin/getcity')}",{'province_id':province_id},function(data){
var data = JSON.parse(data);
console.log(data);
console.log(data['city'].length);
var option=$("<option></option>");
var $select = $("#city_id");
for(var i=0;i<data['city'].length;i ){
$select.append("<option value=" data['city'][i]['name'] ">" data['city'][i]['name'] "</option>");
}
form.render(); //渲染select
})
});
});
layui.use(['form', 'jquery'],function(){
var $ = layui.jquery;
var form = layui.form();
form.on('select(test2)', function(data){
var province_id = $('#province_id').val();
var city_id=data.value;
$.get("{:url('index/Admin/getdistrict')}",{'city_id':city_id,'province_id':province_id},function(data){
var data = JSON.parse(data);
console.log(data);
var option=$("<option></option>");
var $select = $("#district_id");
for(var i=0;i<data['area'].length;i ){
$select.append("<option value=" data['area'][i] ">" data['area'][i] "</option>");
}
form.render();
})
});
});
layui.use(['form', 'jquery'],function(){
var $ = layui.jquery;
var form = layui.form();
form.on('select(demo1)', function(data){
var province_id = data.value;
$.get("{:url('index/Admin/getcity1')}",{'province_id':province_id},function(data){
var data = JSON.parse(data);
console.log(data);
var option=$("<option></option>");
var $select = $("#hostel_id2");
for(var i=0;i<data['building'].length;i ){
$select.append("<option value=" data['building'][i]['name'] ">" data['building'][i]['name'] "</option>");
}
form.render();
})
});
});