一个门店省市店名三级联动
首先看一下三个按钮,
是用UL LI标签 展示,并且用一个隐藏的元素进行记录:
<div class="store_select"><?php $provinces = $this->getAllProvince();?><?php echo $this->__('请前往')?><ul name="store_province_ul" id="store_province_ul" class="store_province_ul"><li><span class="span_store_province" select_value=""><?php echo $this->__('请选择省');?></span></li><?php foreach ($provinces as $row):?><li value="<?php echo $row['province']?>"><span class="span_store_province" select_value="<?php echo $row['province']?>"><?php echo $row['province']?></span></li><?php endforeach;?></ul><input type="hidden" value="" id="store_province" name="store_province" /><img id="load_city_ajax" src="<?php echo $this->getSkinUrl('images/ajax-loader.gif');?>" /><ul name="store_city_ul" id="store_city_ul" class="store_city_ul"><li><span class="span_store_city" select_value=""><?php echo $this->__('请选择市');?></span></li></ul><input type="hidden" value="" name="store_city" id="store_city" /><img id="load_title_ajax" src="<?php echo $this->getSkinUrl('images/ajax-loader.gif');?>" /><ul name="store_title_ul" id="store_title_ul" class="store_title_ul"><li><span class="span_store_title" select_value=""><?php echo $this->__('请选择门店')?></span></li></ul><input type="hidden" value="" name="store_title" id="store_title" /><?php echo $this->__('门店选购')?><!-- <a href="#tip" id="fancy-option" style="display:none"></a> --><span class="send_mobile"><a id="send_mo_btn" href="#send_add_mobile"><?php echo $this->__('地址发送到手机');?></a></span><span class="view_store"><a href="<?php echo $this->getUrl().'store-locator-list';?>"><?php echo $this->__('查看门店地图');?></a></span></div>
2.然后看下JS,逻辑是这样的
我们要进行选择的是三个UL LI 下的元素。
为了模拟SELECT 效果,其逻辑略复杂,具体看代码
<script type="text/javascript"> /* storelocator/getstorelocator/getCityByProvince' */ (function($){ $('#load_city_ajax').hide();$('#load_title_ajax').hide();//将所有有值的身份进行隐藏:$('.span_store_province').each(function(){if ($(this).attr('select_value') == '') {$(this).parent().show();} else {$(this).parent().hide();}})//点击一个省份$('.span_store_province').live("click",function() {var select_province = $(this).attr('select_value');var expand = false;//目前展开状态:TRUE:展开,FLASE:闭合$('.span_store_province').each(function (){if ($(this).attr('select_value') != select_province && $(this).parent().is(":visible") == true) {expand = true;}})if (expand == false) {//需要展开所有的LI$('.span_store_province').each(function (){$(this).parent().show();})} else {//需要关闭其他的LI,$('.span_store_province').each(function (){if ($(this).attr('select_value') != select_province) {$(this).parent().hide();} else {$(this).parent().show();}})//并且AJAX刷新CITY内容$('#store_province').val($(this).attr('select_value'));var curr_province = $('#store_province').val();if (curr_province) {$('#store_city_ul').hide();$('#load_city_ajax').show();$.getJSON("<?php echo $this->getUrl('storelocator/getstorelocator/getCityByProvince');?>",{province:curr_province}, function(data){var res = '<li><span class="span_store_city" select_value="">请选择市</span></li>';$.each(data, function(i,item){var city = item.city;res += '<li style="display:none;"><span class="span_store_city" select_value="'+city+'">' + city + '</span></li>';});$('#store_city_ul').html(res);$('#load_city_ajax').hide();$('#store_city_ul').show();});var res = '<li><span select_value="" class="span_store_title">请选择门店</span></li>';$('#store_title_ul').html(res);$('#load_title_ajax').hide();$('#store_title_ul').show();} else {var res = '<li><span select_value="">请选择市</span></li>';$('#store_city_ul').html(res);$('#load_city_ajax').hide();$('#store_city_ul').show();}}})$('.span_store_city').live("click",function() {var select_city = $(this).attr('select_value');var expand = false;//目前展开状态:TRUE:展开,FLASE:闭合$('.span_store_city').each(function(){if ($(this).attr('select_value') != select_city && $(this).parent().is(":visible") == true) {expand = true;}})if (expand == false) {$('.span_store_city').each(function (){$(this).parent().show();})} else {//关闭其他CITY$('.span_store_city').each(function (){if ($(this).attr('select_value') != select_city) {$(this).parent().hide();} else {$(this).parent().show();}})//请求其他的店铺TITLE$("#store_city").val($(this).attr('select_value'));var curr_city = $("#store_city").val();$('#store_title_ul').hide();$('#load_title_ajax').show();if (curr_city) {$.getJSON("<?php echo $this->getUrl('storelocator/getstorelocator/getTitleByCity');?>",{city:curr_city}, function(data){var res = '<li><span select_value="" class="span_store_title">请选择门店</span></li>';$.each(data, function(i,item){var title = item.title;res += '<li style="display:none;"><span class="span_store_title" select_value="'+title + '">' + title + '</span></li>';});$('#store_title_ul').html(res);$('#load_title_ajax').hide();$('#store_title_ul').show();});} else {var res = '<li><span select_value="" class="span_store_title">请选择门店</span></li>';$('#store_title_ul').html(res);$('#load_title_ajax').hide();$('#store_title_ul').show();}}})$('.span_store_title').live('click',function(){select_title = $(this).attr('select_value');var expand = false;//目前展开状态:TRUE:展开,FLASE:闭合$('.span_store_title').each(function(){if ($(this).attr('select_value') != select_title && $(this).parent().is(":visible") == true) {expand = true;}})if (expand == false) {//展开所有的$('.span_store_title').each(function(){$(this).parent().show();})} else {//闭合其他的$('.span_store_title').each(function(){if($(this).attr('select_value') != select_title) {$(this).parent().hide();}})}$("#store_title").val(select_title);})})(jQuery); </script>
最后提一下上面2处有使用到AJAX访问请求,
方法是PHP写的:
<?php
class Bysoft_StoreLocator_GetstorelocatorController extends Mage_Core_Controller_Front_Action
{ public function getStoreLocatorAction(){$this->loadLayout();$this->renderLayout();}/** 从省名获取所有的城市名*/public function getCityByProvinceAction() {$read= Mage::getSingleton('core/resource')->getConnection('core_read');$province = $_REQUEST['province'];$city_arr = array();$sql = "SELECT `city` FROM `store_locator` WHERE `province` = '{$province}'GROUP BY `city`";echo json_encode($read->fetchAll($sql));}/** 从城市名获取各个店名*/public function getTitleByCityAction() {$read= Mage::getSingleton('core/resource')->getConnection('core_read');$city = $_REQUEST['city'];$title_arr = array();$sql = "SELECT `title` FROM `store_locator` WHERE `city` = '{$city}'GROUP BY `title`";echo json_encode($read->fetchAll($sql));}/** 从店名获取店信息(仅获取一条)*/public function getAddByTitleAction() {$read= Mage::getSingleton('core/resource')->getConnection('core_read');$title = $_REQUEST['title'];$sql = "SELECT * FROM `store_locator` WHERE `title` = '{$title}'limit 1";$results = array();foreach ($read->fetchAll($sql) as $row) {$address = $row['address'];$add_phone = explode(' ',$row['address']);if (isset($add_phone[0])) {$row['address'] = $add_phone[0];} else {$row['address'] = '';}if (isset($add_phone[1])) {$row['telephone'] = $add_phone[1];} else {$row['telephone'] = '';}$results[] = $row;}echo json_encode($results);}
}
纯属个人学习原创,如有问题,请多指教。
谢谢。
一个门店省市店名三级联动相关推荐
- 基于layui实现的省市县区三级联动下拉选择器
基于layui实现的省市县区三级联动下拉选择器 关于layui 这里不做介绍,直戳我阅读 关于本省市区级联下拉选择器 本选择器已经将它封装成一个layui的插件,使用起来非常方便,支持一个页面中使用多 ...
- 全国全国各个省市数据库 三级联动 无刷新数据库
全国全国各个省市数据库 三级联动 无刷新数据库 --创建DBPromary数据库 create database DBPromary use DBPromary go --创建promary ...
- layui的插件,省市县区三级联动下拉选择器
layui的插件,省市县区三级联动下拉选择器 https://fly.layui.com/extend/layarea/#download
- 2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
联动的数据结构,可以参考 // A code blocklist: [{value: 1,label: '中国',children: [{value: 2,label: '广东',children: ...
- 省市区县三级联动后台接口设计
1,数据库设计: CREATE TABLE `dc_area_city` ( `id` int(11) NOT NULL AUTO_INCREMENT, `area_id` int(11) D ...
- ajax省市线三级联动
<script type='text/javascript' src='http://ajax.useso.com/ajax/libs/jquery/1.7.2/jquery.min.js?ve ...
- v-distpicker 一个好用的三级联动的插件
// 引入插件npm install v-distpicker --saveimport VDistpicker from 'v-distpicker'Vue.component('v-distpic ...
- 小程序 省市区县三级联动选择器(caseCade)
picker组件 <view class="section"><picker mode="region" bindchange="b ...
- 省市县区三级联动下拉选择器
文档:https://fly.layui.com/extend/layarea/#doc 下载:https://fly.layui.com/extend/layarea/#download
最新文章
- Java数据结构——解析算术表达式
- scala之Actors
- python32-python32和
- 红薯因 Swift 重写开源中国失败,貌似欲改用 Python
- pycharm怎么查看代码结构,看函数定义、变量定义、类定义索引、目录?(左方structure)
- 深度学习笔记第一门课​第四周:深层神经网络
- linux下GPRS模块的应用程序
- 电脑故障扫描修复软件_253个电脑故障修复工具
- druid mysql配置详解_druid 参数配置详解
- 关于net2.0里面新出现的类backgroundworker的应用
- 机房收费系统--需求文档
- Python numpy函数:shape用法
- 国内各运营商(ISP)IP段表
- phusion passenger standalone
- xgboost模型训练出来的错误Error during wrapup: NA/NaN argument
- 申报快结束!2022年武汉经开区在孵企业房租申报奖励补贴补助、申报条件材料
- 【Linux】用最形象的例子学习进程,从入门到深入
- BERT-MRC:统一化MRC框架提升NER任务效果
- 服务器除尘网站,浪潮服务器除尘清洗
- centos7 更新网络源,下载扩展源时出现“one of the configured repositories failed”提示,解决方案
热门文章
- CEF Debug模式运行打开网页白屏
- android+省电程序,Android5.1 系统之省电模式探索一启动流程
- 温度补偿计算公式_自动温度补偿原理与调节方法
- 基于GEE平台土地类型分类
- 10年计算机速度慢加固态硬盘行不行,电脑越来越慢?你的ssd固态硬盘分区弄好了吗...
- 草地天空全套26张英文字母
- powerlevel10k 颜色和图标的自定义设置
- 数据中心的边缘效应论
- 中医理论质疑文章集锦
- python replace替换多个字符_Python 同时替换多个字符串