html - 我想使用 CSS 更改类的属性值
问题描述
我想使用 CSS 更改类的属性值。例如:html代码为:
<a href="https://www.google.com/" title="My Account"> My Account </a>
假设我需要将 href 更改为,href="https://www.stackoverflow.com/"
或者我想将标题更改为title="Go To Your Account"
我想使用 CSS 来做到这一点。我使用此 CSS 代码更改标题属性,但它隐藏了元素本身
a[title="My Account"]{
visibility:hidden;
}
a[title="My Account"]:before{
content: "Go To Your Account|";
}
解决方案
您可以使用 javascript 来做到这一点。您还可以使用 jquery 库来少写多写代码
<a id="my_acc" href="#acc" title="My Account"> My Account </a>
<script>
var my_acc = document.getElementById("my_acc");
my_acc.addEventListener("click", function(){
this.setAttribute("title", "Go to your Account");
});
</script>
N:您需要在 html 中的 body 标记末尾添加 javascript 以使用事件侦听器
推荐阅读
- wordpress - 在没有 GULP 的情况下使用 WordPress 主题
- firebase - Flutter firebase 流有数据但返回 null
- performance - 优化 ifort 和 gfortran 并比较运行时间
- laravel - 如何设置带有子域的 Laravel 应用程序以在 cPanel 服务器上工作?
- python - 如何使用熊猫根据某些条件更改列的值?
- python - 为多元预测创建 LSTM 模型时遇到问题
- java - 如何在 Hibernate HSQL 数据库中创建视图
- c++ - 这个 Visual Studio 编译器错误“除以或除以零”是一个错误吗?
- macos - macOS 上的 Swiftui 表单标签对齐
- r - 将箱线图异常值放入表中