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

相关文章

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

springboot下载接口限速功能实现

《springboot下载接口限速功能实现》通过Redis统计并发数动态调整每个用户带宽,核心逻辑为每秒读取并发送限定数据量,防止单用户占用过多资源,确保整体下载均衡且高效,本文给大家介绍spring... 目录 一、整体目标 二、涉及的主要类/方法✅ 三、核心流程图解(简化) 四、关键代码详解1️⃣ 设置

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项