문제는 내 외부 JavaScript 파일이 내 html로 작동하도록하는 것입니다.외부 자바 스크립트가 작동하지 않습니다.
자바 스크립트의 요점은 비어있는 상태로 제출할 때 필수 입력란을 강조 표시 한 다음 클릭하거나 (onfocus) 클릭하면 원래 색상으로 돌아가는 것입니다.
내가 정확하게 그것이 내가 온로드 = 사용하여 시도 html로
에 적용하기 위해 자바 스크립트를 연결하는 방법을 모른다 "기능을();" < body>하지만 그게 옳지 않다는 것을 압니다. 나는 완전히 잃어 버렸기 때문에 어떤 도움이나지도라도 크게 감사 할 것입니다. 여기
HTML : 여기 http://pastebin.com/Zwsqn7kr
CSS : 여기 http://pastebin.com/zpNkpALd
자바 스크립트 :
window.onload = function() {
document.getElementById('mainForm').onsubmit = function (e) {
var t = document.getElementsById("title");
var d = document.getElementsById("description");
var l = document.getElementsById("license");
var tv = document.getElementsById("title").value;
var dv = document.getElementsById("description").value;
if (tv == null || tv === "") {
e.preventDefault();
title.style.backgroundColor = "red";
title.parentNode.style.backgroundColor = "red";
}
if (dv == null || dv === "") {
e.preventDefault();
description.style.backgroundColor = "red";
description.parentNode.style.backgroundColor = "red";
}
if (!l.checked) {
e.preventDefault();
license.style.backgroundColor = "red";
license.parentNode.style.backgroundColor = "red";
}
t.onfocus = function() {
title.style.backgroundColor = "white";
title.parentNode.style.backgroundColor = "white";
};
d.onfocus = function() {
description.style.backgroundColor = "white";
description.parentNode.style.backgroundColor = "white";
};
l.onfocus = function() {
license.style.backgroundColor = "EBF4FB";
license.parentNode.style.backgroundColor = "EBF4FB";
};
};
};
무엇을하고 있거나하지 않습니까? * "작동하지 않습니다"* 디버깅 할 수 없습니다. –
자바 스크립트가 HTML에 올바르게 링크되어 있다고 생각하지 않습니다. – Zippo
콘솔에 어떤 오류가 표시됩니까? – tousif