使用 JavaScript 获取输入标签内属性的值

Get value of attribute inside input tag using JavaScript

本文关键字:属性 标签 JavaScript 获取 输入 使用      更新时间:2023-09-26

我尝试使用 JavaScript 从 <input> 元素内的属性中获取值,但结果没有显示。这是我的代码:

document.getElementsByClassName('button').getAttribute('onClick')[0].innerHTML;

这是我的 HTML:

<input type="button" class="button" value="Login to download" onclick="js:self.location='login.php?ret=view&b=55212'"><br/>

我想获取onclick中的值。

getElementsByClassName

返回数组

不是

getAttribute

所以

document.getElementsByClassName('button').getAttribute('onClick')[0].innerHTML;

应该是

document.getElementsByClassName('button')[0].getAttribute('onClick');

 onClick  != onclick

试试这个:

document.getElementsByClassName('button')[0].getAttribute('onClick')

这会给你

js:self.location='login.php?ret=view&b=55212'
相关文章: