你需要傳遞參數event
到submitProffs
功能
// save global scope
(function(){
'use strict';
// protect from hoisting
var mainFunc,
submitProffs;
submitProffs = function (event) {
var VacBrand = document.getElementById("txtAcBrand").value;
if (VacBrand == "") {
alert("Please Select your Ac Brand!");
event.preventDefault();
// if you need disable bubbling
// event.stopPropagation();
}
};
mainFunc = function (event) {
// listen event on element
// replace 'click' to your event
document.addEventListener("click", submitProffs, false);
};
// code run when html DOM ready
document.addEventListener("DOMContentLoaded", mainFunc);
}());
它是如何工作看到有https://jsfiddle.net/2gew6nLo/
just in firefox? –