Jquery实现仿京东商城省市联动菜单_jquery
程序员文章站
2023-12-22 16:41:46
...
本文实例讲述了Jquery实现仿京东商城省市联动菜单的简单实例代码。分享给大家供大家参考。具体如下:
运行效果截图如下:
'),
$ul = $(''+this.name+'
');
$.each(city, function(){
$ul.append(''+this+' ');
});
$tabs.children('ul').append('市区 ');
$tabs.append($div.addClass('region').append($ul));
$tabs
.tabs( "refresh" )
.tabs('option', 'active', 1)
.data('address', $this.text());
})
.on('click', '.city', function(){
var $this = $(this),
$tabs = $this.parents('.selectAddress'),
$div = $(''),
$ul = $(''+this+' ');
});
$tabs.children('ul').append('县区 ');
$tabs.append($div.addClass('region').append($ul));
$tabs
.tabs( "refresh" )
.tabs('option', 'active', 2)
.data('address', $tabs.data('address')+'/'+$this.text());
}else{
//获取值并赋值至文本框中
$('.address').val($tabs.data('address')+'/'+$this.text());
$tabs.parent().hide();
}
})
.on('click', '.county', function(){
var $this = $(this),
$tabs = $this.parents('.selectAddress');
$('.address').val($tabs.data('address')+'/'+$this.text());
$tabs.parent().hide();
})
;
$(document).bind('click', function(e){
var $target = $(e.target),
addressInfo = $('#addressInfo');
if(!$target.hasClass('selectAddress')
&& $target.parents('.selectAddress').size() == 0
&& !$target.is($('.address'))
&& addressInfo.is(':visible')){
$('#addressInfo').hide();
}
});
})
运行效果截图如下:
具体代码如下:
Document