Javascript가 잘못된 순서로 이벤트를 처리 할 수있어 혼란 스럽습니다. windows/chrome에서 아래의 코드는 클래스가 변경되기 전에 클래스가 변경된 객체를 콘솔에 출력하지만 클래스 만 출력하면 변경되지 않은 클래스가 표시됩니다. 어떤 사람이 이것을 통치하는 규칙을 설명해 주시겠습니까? 나는 내 물건을 볼 수있는 상태를 예상하는 방법을 모른다.자바 스크립트가 순차적으로 작동하지 않습니다.
는<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Table Schema</title>
</head>
<body>
<a href="#" class="first_class" onclick="checkClass(this)">I am supposed to be first_class!</a>
<script>
function checkClass(obj) {
console.log(obj);
console.log(obj.className);
if (obj.className == 'first_class') {
obj.className = 'second_class';
}
}
</script>
</body>
</html>
<html>
은 문자열이있는 나를위한 첫 번째 클래스를 말하고 obj는 그 순간의 스냅 샷이 아니라 최신 값을 표시합니다. https://stackoverflow.com/questions/30150469/why-console-log-displays-incorrect-objects-values – epascarello