I am new in JS, and meet a problem, asking for some suggestions, really appreciated.
The question is I don't know how to obtain the value in a button by an independent method, the codes are below:
I:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<input type="button" id="btn1" value="A" onclick="alert(btn1.value);"/>
</body>
</html>
By using this code, I could get the value which is "A"
II:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function showID() {
alert(this.id);
}
</script>
</head>
<body>
<input type="button" id="btn1" value="A" onclick="showID()"/>
</body>
</html>
III:
Code:
<head>
<title></title>
<script type="text/javascript">
function showIDByTagName() {
var btn = document.getElementsByTagName("input");
alert(btn.id);
}
</script>
</head>
<body>
<input type="button" id="btn1" value="A" onclick="showIDByTagName()"/>
</body>
</html>
However, by II and III, it alerts the value of the button is "undefined", really confused

, looking for some help, thank you very much