Javascript如何获取外部div元素的alt文本

时间:2018-07-01 12:47:58

标签: javascript

<div class="Thumbnail__thumbnail___3ABuK Thumb__thumbnail___jO6WM Video__thumbnail___2vJC9">
<img alt="alttext" src="https:/">
<div class="Duration__duration___qiPOI">14:57</div></div>

window.external.menuArguments.event.srcElement.innerHTML;

给出上述结果。然后如何获取img的alt值?

(我正在使用

window.ActiveXObject("WScript.Shell")

1 个答案:

答案 0 :(得分:0)

似乎唯一的方法是操纵字符串;

var alt = window.external.menuArguments.event.srcElement.innerHTML;
if (alt.search("img alt=") > 0) alt = alt.substring(alt.lastIndexOf('img alt="') +9, alt.lastIndexOf('src') -2);

[04.07.2018]我终于找到了;

window.external.menuArguments.event.srcElement.getElementsByTagName('img')[0].alt;