我想检索链接的HTML属性,并应用于模态按钮
我有一个链接列表和一个在单击时弹出的模态。我要实现的只是每当我单击任何链接时,都会检索该链接的HTML属性并应用于模态按钮。
<body x-data="{ extModal : false }">
<ul>
<li><a @click="extModal = !extModal" href="http://examplelink-1.com"></a></li>
<li><a @click="extModal = !extModal" href="http://examplelink-2.com"></a></li>
<li><a @click="extModal = !extModal" href="http://examplelink-3.com"></a></li>
</ul>
<div x-show="extModal">
<h2>External Link Alert</h2>
<p>Are you sure you want to leave this site?</p>
<button @click="extModal = false">No</button>
<!-- Dynamic link update -->
<a href="" @click="extModal = false" target="_blank">Yes</a>
</div>
</body>
I have a list of links and a modal that pops up on click. All i want to achieve is whenever i click on any of the links, retrieve the html attribute of that link and apply to the modal button.
<body x-data="{ extModal : false }">
<ul>
<li><a @click="extModal = !extModal" href="http://examplelink-1.com"></a></li>
<li><a @click="extModal = !extModal" href="http://examplelink-2.com"></a></li>
<li><a @click="extModal = !extModal" href="http://examplelink-3.com"></a></li>
</ul>
<div x-show="extModal">
<h2>External Link Alert</h2>
<p>Are you sure you want to leave this site?</p>
<button @click="extModal = false">No</button>
<!-- Dynamic link update -->
<a href="" @click="extModal = false" target="_blank">Yes</a>
</div>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗨,欢迎@demeyo。
我目前正在手机上,无法测试,但是我将尝试解释您如何简单地实现自己想要的东西。
看起来可能如下:
提示:您可以使用
x-for
指令将链接循环并渲染。Hi and welcome @demeyo.
I am currently on my phone and can not test it, but I will try to explain how you could simply achieve what you want.
That could look like follows:
Hint: You could use the
x-for
directive to loop over your links and render them.