2013-09-24 74 views
0

我试图从使用JavaScript的<input>元素中的属性获取值,但结果未显示。这里是我的代码:使用JavaScript获取输入标签内属性的值

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值。

回答

0

试试这个:

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

这会给你

js:self.location='login.php?ret=view&b=55212' 
+0

非常感谢你的工作!你让我开心 :) –

2
getElementsByClassName 

返回数组

不是

getAttribute 

所以

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

应该

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

而且

onClick != onclick 
+0

感谢您的快速答复仍然无法工作 –

+0

@ user1611864有一个typo.Check编辑。 –

+0

然后你想要什么?不是完整的字符串? –

相关问题