html - 在两个 svg 图标之间切换
问题描述
如何svg xmlnx
在此处放置另一个链接,以便在单击第一个 svg 时,它会切换到另一个 svg 链接?
我的html:
<div class="input-box" *ngIf="loginForm.controls.password.untouched || loginForm.controls.password.valid">
<input placeholder="***********" name="password" id="password" [type]="show ? 'text' : 'password'" formControlName="password" autocomplete="on">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" (click)="password()">
<path d="M10 12a2 2 0 100-4 2 2 0 000 4z" />
<path fill-rule="evenodd"d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z"clip-rule="evenodd" />
</svg>
</div>
解决方案
You can add javascript to change the attribute.
<input placeholder="***********" name="password" id="password" [type]="show ? 'text' : 'password'" formControlName="password" autocomplete="on">
<svg xmlns="http://www.w3.org/2000/svg" onclick="changesvg()" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" (click)="password()" id="Svg">
<path d="M10 12a2 2 0 100-4 2 2 0 000 4z" />
<path fill-rule="evenodd"d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z"clip-rule="evenodd" />
</svg>
</div>
<script>
var Source = true
var Svg=document.getElementById("Svg")
function changesvg(){
Source= !Source
console.log(Source)
if (Source==true){
Svg.setAttribute("xmlns","http://www.w3.org/2000/svg")
}
else{
Svg.setAttribute("xmlns","New link")
}
}
</script>
推荐阅读
- javascript - 如何在包含必须使用双引号的 JSON 字符串的数据设置值周围添加单引号?
- html - 当它所在的元素在悬停时设置为较低的值时,如何使工具提示的不透明度为 1
- wordpress - 即使凭据正常也无法连接到 SFTP 服务器
- c# - OnTriggerEnter 调用两次
- node.js - 在 TypeScript 中使用 Promise 的 setTimeout() 和 clearTimeout()(严格模式 + 所有注释)
- javascript - NodeJS - 读取 Parquet 文件
- pytorch - 如何在 FloatTensor、Pytorch 中更改(分配)新值?
- assembly - 如何使用/链接 .lib 文件作为使用 TASM 汇编器的库?
- dropbox - 在 Dropbox 中看不到以前版本的菜单选项
- sql - 如何使用另一个表中的日期列过滤一个表的开始和结束日期