用JS函数获取点击链接的属性 [英] Get attribute of clicked link with JS function
本文介绍了用JS函数获取点击链接的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有html结构:
<a onclick="setString()">
<img alt="no" />
</a>
我需要获取被点击的 a
属性,例如 alt
.
I need to get attribute of a
,that had been clicked,e.g. alt
.
如何通过setString()js函数知道
单击具有什么 alt
属性的图像?
How to know with setString() js function ,
image with what alt
attribute is clicked?
我以某种方式认为 this
,但是不知道如何.
I assume,that somehow with this
,but don't know how.
推荐答案
我将更改HTML以删除不需要的位...
I would change my HTML to remove the bits that aren't needed...
<img alt="no" onclick="setString(this.alt);" />
如果需要,可以使用CSS设置样式,而不是将图像包装在锚定标记中.
Rather than wrapping the image in an anchor tag, style it with CSS if you want...
cursor: pointer;
这篇关于用JS函数获取点击链接的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文