【发布时间】:2017-09-27 20:54:09
【问题描述】:
在我的 html 页面中,我想在其 href 点击时获取 html 节点。
示例:
HTML 文件
<!DOCTYPE html>
<html>
<body>
<p><a href="https://www.w3schools.com/html/" data-type="W3">Click1</a></p>
<p><a href="https://www.google.com/html/" data-type="google">Click2</a></p>
</body>
</html>
当Click1 被点击时,我想要赋值:W3
当Click2 被点击时,我想重视:google
目前,我正在使用document.documentElement.outerHTML 获取完整的 html 字符串并对其进行解析。有没有更好的方法在点击 href 时获得 data-type 值?
【问题讨论】:
标签: javascript jquery html dom