我遇到的問題是讓我的外部JavaScript文件與我的html一起工作。外部javascript將不起作用
JavaScript的要點是當它們被提交爲空時突出顯示必填字段,然後在點擊或(onfocus)時返回到其原始顏色。
我不知道如何正確地鏈接的JavaScript,使之適用於HTML
我使用的onload =試圖「功能();」在<身體內>但我知道這是不正確的。我完全失去了,所以任何幫助或指導將不勝感激。
HTML瀏覽:http://pastebin.com/Zwsqn7kr
此處的CSS:http://pastebin.com/zpNkpALd
的JavaScript這裏:
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";
};
};
};
它在做什麼或不做什麼? *「不起作用」*不可調試。 – 2014-09-26 18:34:20
我不認爲JavaScript正確鏈接到的HTML如果在 – Zippo 2014-09-26 18:35:29
它顯示在控制檯中顯示什麼錯誤。 – tousif 2014-09-26 18:40:33