<html>
<head>
<title>Calculator</title>
<style type = "text/css">
#calculator{
width:164px;
top:20%;
right:50%;
position:absolute;
border:1px black solid;
background-image:url('images.jpg');
}
#matrix
{
float:right;
border:1px black solid;
width:100px;
}
#row1{
position:relative;
width:17px;
}
</style>
</head>
<body>
</div>
<div id = "matrix">
<form>
<table>
<tr><td style = "width:40px"><input type = "text" id = "one"></input></td>
<input type = "number" id = "two"></input></td></tr>
<tr><td><input type = "number" id = "three"></input></td>
<input type = "number" id = "four"></input></td></tr>
</table>
<input type = "submit" value = "count" onclick = "calculate();"></input>
</form>
</div>
<script language = "javascript" type = "text/javascript">
function calculate(){
var a = document.getElementById('one').value;
alert(a);
}
</script>
</body>
</html>
해당 함수에서 id가 제대로 접근 할 수 없으므로 해당 변수를 경고하려고 할 때 경고 상자가 비어 있습니다. 내 머리 속에 자바 스크립트 코드가 있지만 이전에는 작동하지 않았다. 본문 섹션으로 이동하면 상황이 바뀌지 않았다. 아무도 자바 스크립트에서이 오류를 해결할 수 있다면 큰 도움이 될 것이다. jquery를 쓰지 마라. 대안으로 코드. 탄약.GetElementById 자바가 값에 액세스 할 수 없습니다.
참고로, 'input' 요소에는 별개의''닫는 태그. –
귀하의 HTML 형식이 잘못되었습니다 (여는 태그가없는 닫는''태그가 있음), 여전히 작동합니다 : http://jsfiddle.net/KBv82/ – Blender
'' '과' '사이의 공백을 제거하면 어떻게됩니까? = '속성에 대해' '요소마다 별도의 닫는 태그를 넣지 마십시오? – Dai