Form.onsubmit 不工作
Form.onsubmit not working
我正在创建一个脚本来检查我的代码中的某些内容。此脚本 运行 在 Chrome 上成功,但在 IE 上 运行 不成功。
这是 onsubmit
上的 运行 我的表单
<form id="frm1" name="frm1" method="post" onsubmit="return checkForm();" action="save_dept_add.php">
这是我的脚本(我把它放在了 head 标签中)
<script language="javascript" type="text/javascript">
function checkForm()
{
if (!window.console) {
console = { log: function(){} };
}
var e = document.getElementById("dept");
var xtext = e.options[e.selectedIndex].text;
if(xtext == ""){
console.log("no dept");
alert("Please select your department");
return false;
}else{
console.log(xtext);
var q = document.getElementById("quantity");
var check = q.value;
console.log(check);
if(check == ""){
alert("Please insert a quantity");
return false;
}else{
return true;
}
}
}
谁能告诉我哪里出了问题?
将此添加到 JavaScript 文件的顶部
if (!window.console) {
console = { log: function(){} };
}
我正在创建一个脚本来检查我的代码中的某些内容。此脚本 运行 在 Chrome 上成功,但在 IE 上 运行 不成功。
这是 onsubmit
上的 运行 我的表单
<form id="frm1" name="frm1" method="post" onsubmit="return checkForm();" action="save_dept_add.php">
这是我的脚本(我把它放在了 head 标签中)
<script language="javascript" type="text/javascript">
function checkForm()
{
if (!window.console) {
console = { log: function(){} };
}
var e = document.getElementById("dept");
var xtext = e.options[e.selectedIndex].text;
if(xtext == ""){
console.log("no dept");
alert("Please select your department");
return false;
}else{
console.log(xtext);
var q = document.getElementById("quantity");
var check = q.value;
console.log(check);
if(check == ""){
alert("Please insert a quantity");
return false;
}else{
return true;
}
}
}
谁能告诉我哪里出了问题?
将此添加到 JavaScript 文件的顶部
if (!window.console) {
console = { log: function(){} };
}