Использование console.log будет работать каждый раз, но алерт может быть заблокирован, и функция не будет вызываться.
Вы можете отобразить свое собственное оповещение, если вам нужно.
Вероятно, вам следует переместить обработчик событий из встроенного:
HTML:
<form action='#' id="my-form">
<input type='text' name='asdf'/>
<input type='submit' name='jkl' value='Submit'/>
</form>
JS:
document.getElementById('my-form').onsubmit = function() {
console.log("asdf");
return false;
}
Firefox remove
содержит функцию, содержащую alert
, поэтому вам нужно переместить alert out of your function
:
Это позволит вам вернуть значение false, даже если оповещение отключено!
document.getElementById('my-form').onsubmit = function() {
console.log("asdf");
displayAlert();
return false;
}
function displayAlert() {
alert("test");
}
JsFiddle: http://jsfiddle.net/ghorg12110/nddtf13q/
Чтобы отобразить персонализированное оповещение:
Этот код отобразит настраиваемое окно оповещения, которое Firefox не может заблокировать с помощью div. Вы должны сделать немного CSS, чтобы сделать его таким, как вы хотите, но основная идея здесь:
HTML:
<form action='#' id="my-form">
<input type='text' name='asdf' />
<input type='submit' name='jkl' value='Submit' />
</form>
<div id="alertBox">
<div id="alertContent">asdf</div>
<button id="alertOK">OK</button>
</div>
CSS:
#alertBox {
display:none;
background: grey none repeat scroll 0 0;
left: 50%;
margin-left: -275px;
position: fixed;
text-align: center;
width: 550px;
z-index: 10;
}
JS:
document.getElementById('my-form').onsubmit = function () {
displayAlert("asdf");
return false;
}
function displayAlert(msg) {
document.getElementById('alertContent').innerHTML = msg;
document.getElementById('alertBox').style.display = "block";
document.getElementById('alertOK').onclick = function () {
document.getElementById('alertBox').style.display = "none";
};
}
JsFiddle: http://jsfiddle.net/ghorg12110/dkruqsqv/
person
Magicprog.fr
schedule
30.06.2015
alert
и его исторической дурацкости я полагаю, что это старый добрый баг. Фрагмент может помочь! - person Kyll   schedule 30.06.2015alert
и используйтеconsole.log
- person Hacketo   schedule 30.06.2015console.log
не вариант. Это должно быть сообщение для пользователя, который заполняет форму - person chillichief   schedule 30.06.2015