jQuery国际区号使用button实现下拉选择(仿知乎效果)

2023-10-19 08:59

本文主要是介绍jQuery国际区号使用button实现下拉选择(仿知乎效果),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果预览
在这里插入图片描述
在这里插入图片描述

1、jQuery

2、html 按钮

3、国际区号 json

1、jQuery版本

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

2、html 按钮

 <div class="box"><div class="phoneBox"><div class="phoneGroup"><button class="phone-btn selectBtn" type="button" data-type="selected"><span>中国 +86</span><svg class="Zi--Select Select-arrow" fill="currentColor" viewBox="0 0 24 24"><pathd="M12 16.183l2.716-2.966a.757.757 0 0 1 1.064.001.738.738 0 0 1 0 1.052l-3.247 3.512a.758.758 0 0 1-1.064 0L8.22 14.27a.738.738 0 0 1 0-1.052.758.758 0 0 1 1.063 0L12 16.183zm0-9.365L9.284 9.782a.758.758 0 0 1-1.064 0 .738.738 0 0 1 0-1.052l3.248-3.512a.758.758 0 0 1 1.065 0L15.78 8.73a.738.738 0 0 1 0 1.052.757.757 0 0 1-1.063.001L12 6.818z"fill-rule="evenodd"></path></svg></button></div><div class="selectConentent"><div class="selectOptions"></div></div></div></div>
    <style>.box {width: 352px;height: auto;background-color: #ffffff;margin: 60px auto;border-bottom: 1px solid #eeeeee;}.phoneBox {position: relative;display: inline-block;}.phoneGroup {display: inline-block;min-width: 72px;text-align: left;}.phone-btn {border: none;height: auto;padding: 0;line-height: inherit;background-color: transparent;border: none;border-radius: 0;display: inline-block;font-size: 14px;line-height: 32px;cursor: pointer;}.phone-btn:focus {outline: none;}.selectBtn {text-align: left;/* padding: 0 16px; */color: #8590a6;text-align: center;background: none;/* border: 1px solid; */border-radius: 3px;height: calc(100% - 42px);}.selectConentent {display: none;position: absolute;top: 0;z-index: 233;background-color: #ffffff;left: -24px;border: 1px solid #ebebeb;width: 210px;border-radius: 4px;-webkit-box-shadow: 0 5px 20px rgba(26, 26, 26, .1);box-shadow: 0 5px 20px rgba(26, 26, 26, .1);}.selectOptions {overflow: auto;position: relative;max-height: 500px;padding: 8px 0;border-radius: 4px;text-align: left;}.selectOptions::-webkit-scrollbar {width: 10px;height: 1px;background-color: #f6f6f6;}/*定义滚动条轨道 内阴影+圆角*/.selectOptions::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3);border-radius: 10px;background-color: #f6f6f6;}.selectOptions::-webkit-scrollbar-thumb {background-color: #afadad;width: 5px;max-height: 10px;border-radius: 10px;}.select-option {display: block;width: 100%;height: 40px;padding: 0 20px;line-height: 40px;color: #8590a6;text-align: left;background: none;border: none;}.Select-arrow {margin-left: 8px;fill: currentcolor;width: 24px;height: 24px;display: inline-block;vertical-align: middle;}</style>

3、jQuery

    <script>$(function () {$("button.selectBtn").click(function (e) {if ($(".selectConentent").is(':hidden')) {$(".selectConentent").show();} else {$(".selectConentent").hide();}$(document).one('click', function () {$(".selectConentent").hide();});e.stopPropagation();});// 国际区号json$.ajax({type: "GET",url: "../js/selectOptions.json",data: "data",dataType: "JSON",success: function (data) {// console.log(data);$.each(data.CountryNum, function (i, item) {// console.log(item.countryName, item.number);let btns = " <button class='phone-btn selectBtn select-option' type='button' data-type='option'" + "data-id=" + i + ">" + item.countryName + "   " + item.number + "</button>";$(".selectOptions").append(btns);chooseBtn();// console.log(btns);});}});function chooseBtn() {$("button[data-type='option']").each(function () {$(this).click(function () {let txt = $(this).text();$("button[data-type='selected']").attr("data-fid", $(this).index());$("button[data-type='selected'] span").text(txt);$(".selectConentent").hide();});$(this).hover(function () {$(this).css("background-color", "#f6f6f6");}, function () {$(this).css("background-color", "#ffffff");});});};});

效果:
点击button
显示下拉选框
3、json文件
国际区号json文件

https://download.csdn.net/download/Sonnenlicht77/12355582

这篇关于jQuery国际区号使用button实现下拉选择(仿知乎效果)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/238766

相关文章

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U

使用Python创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

Git可视化管理工具(SourceTree)使用操作大全经典

《Git可视化管理工具(SourceTree)使用操作大全经典》本文详细介绍了SourceTree作为Git可视化管理工具的常用操作,包括连接远程仓库、添加SSH密钥、克隆仓库、设置默认项目目录、代码... 目录前言:连接Gitee or github,获取代码:在SourceTree中添加SSH密钥:Cl

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib