SO中文参考
首页
(current)
程序语言
c
java
python
c++
go
javascript
swift
c#
操作系统
linux
ubuntu
centos
unix
数据库
oracle
mysql
mongodb
postgresql
框架
node.js
angular
react-native
avalon
django
twisted
hadoop
.net
移动开发
android
ios
搜索
使用lightbox2后点击图像菜单时出现
问题描述
投票:0
回答:0
css
z-index
lightbox2
最新问题
如何使用 Azure Static Web App with Svelte 连接到 Azure SQL 数据库?
使用 C# 将日期时间插入 Postgre
PayPal 智能/托管按钮:批准/捕获时回调
如何在javascript中检测浏览器选项卡是否关闭或浏览器窗口
当简码在WP中返回空时如何使用Php if语句
尝试添加节点池后,Azure Kubernetes 陷入失败(运行)状态 - 超出配额问题
Googletrans AttibutError
Angular 6 本地化路由器不起作用
更改 fontawesome 图标会丢失“title”元素 元素),通过 ch... 我正在尝试通过更改结果上的类来更改 fontawesome 图标(它会自动从具有 <i> 属性的 title 元素切换到具有嵌套 <svg> 元素的 <title> 元素) <svg>元素。不过,我还需要更新嵌套的 <title> 元素,但我发现更改类将导致嵌套的 <title> 元素被删除。我应该如何更新 <title> 元素?我还可以补充一点,我没有使用任何模块,我只是使用来自 CDN 的 fontawesome 脚本: <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet" type="text/css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/js/all.min.js"></script> const getIconOuterHTML = () => { return new Promise((resolve) => { setTimeout(() => { const iconEl = document.querySelector('#commentIcon'); let output = $('<div>').text(iconEl.outerHTML).html(); //console.log(output); output = output.replaceAll('><', '>\n<'); resolve(output); }, 200); }); } $(document).ready(async () => { document.querySelector('#htmlRepresentation').innerHTML = await getIconOuterHTML(); }); $(document).on('click', '#switchIconBtn', async (ev) => { const iconEl = document.querySelector('#commentIcon'); const titleElId = iconEl.getAttribute('aria-labelledby'); const titleEl = iconEl.querySelector(`#${titleElId}`); if( iconEl.classList.contains('fa-comment-dots') ) { iconEl.classList.remove('fa-comment-dots'); iconEl.classList.add('fa-comment-medical'); if(titleEl !== null){ titleEl.textContent = 'add a comment'; } else { alert('could not find title element'); } } else { iconEl.classList.remove('fa-comment-medical'); iconEl.classList.add('fa-comment-dots'); if(titleEl !== null){ titleEl.textContent = 'edit comment'; } else { alert('could not find title element'); } } document.querySelector('#htmlRepresentation').innerHTML = await getIconOuterHTML(); }); <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet" type="text/css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/js/all.min.js"></script> <i class="fas fa-comment-medical" title="add a comment" id="commentIcon"></i> <div><button id="switchIconBtn" style="margin-top: 15px;">Switch icon and title</button></div> <div>Resulting HTML:</div> <pre id="htmlRepresentation"></pre> 正如您在生成的 HTML 表示中看到的那样,单击更改图标类的按钮将导致 <title> 元素被删除。我应该如何更新标题? 现在检查 const getIconOuterHTML = () => { return new Promise((resolve) => { setTimeout(() => { const iconEl = document.querySelector('#commentIcon'); let output = $('<div>').text(iconEl.outerHTML).html(); //console.log(output); output = output.replaceAll('><', '>\n<'); resolve(output); }, 200); }); } $(document).ready(async () => { document.querySelector('#htmlRepresentation').innerHTML = await getIconOuterHTML(); }); $(document).on('click', '#switchIconBtn', async (ev) => { const iconEl = document.querySelector('#commentIcon'); const titleElId = iconEl.getAttribute('aria-labelledby'); const titleEl = iconEl.querySelector(`#${titleElId}`); if( iconEl.classList.contains('fa-comment-dots') ) { iconEl.classList.remove('fa-comment-dots'); iconEl.classList.add('fa-comment-medical'); if(titleEl !== null){ titleEl.textContent = 'add a comment'; } else { alert('could not find title element'); } } else { iconEl.classList.remove('fa-comment-medical'); iconEl.classList.add('fa-comment-dots'); if(titleEl !== null){ titleEl.textContent = 'edit comment'; } else { alert('could not find title element'); } } // Manually update title const newTitle = document.createElement('title'); newTitle.textContent = titleEl.textContent; iconEl.querySelector('svg').appendChild(newTitle); document.querySelector('#htmlRepresentation').innerHTML = await getIconOuterHTML(); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/js/all.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet"/> <i class="fas fa-comment-medical" title="add a comment" id="commentIcon"></i> <div> <button id="switchIconBtn" style="margin-top: 15px;">Switch icon and title</button> </div> <div>Resulting HTML:</div> <pre id="htmlRepresentation"></pre>
将字典写入 Excel - Python-Pandas
如何使用 Zig ABI 处理 C 中的 Zig 错误集
如何识别Assets.xcassets中添加的资源是否在项目中使用?
为什么MySQL外键约束名称必须是唯一的?
为什么从代理构造函数构造的实例不调用代理陷阱?
欧拉项目#7 Python
将 .NET 8 程序集加载到 Matlab R2023a 时出现问题
Flutter flutter_local_notifications 当点击通知时,打开特定页面
如何在Android模块中添加模块?
如何使用 WMI 从控制器检索域用户信息
如何在 TwentyTwentyThree 主题中将 interactivity.js 放入我自己的 (PHP) 模板中?
© www.soinside.com 2019 - 2024. All rights reserved.