javascript:表单不仅被IE取代,而且,它适用于所有其他浏览器
javascript: Form is not getting submiited only IE, but, it works all other browsers
在此代码上,它运行良好,它检查所有if
条件,并且在除IE8和IE以外的所有浏览器中都可以。 当正确输入所有登录值时,那么,在提交表单时,它可以在除IE,IE8以外的所有浏览器中工作,为什么它在IE8中不起作用?有什么线索吗?
当所有输入都正常时,将显示以下内容。这在IE8中不起作用。有什么帮助吗?
<div id="FormSubmit" class="FormSubmit">
<p>Form submitted successfully</p>
</div>
我不知道确切的问题在哪里。它适用于其余浏览器。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<!--[if IE]>
<link rel="stylesheet" href="IEStyles.css" type="text/css" media="screen" />
<![endif]-->
</head>
<body>
<div class="container">
<div id="FormSubmit" class="FormSubmit">
<p>Form submitted successfully</p>
</div>
<div class="LogIn">
<form name="loginForm" method="post" onsubmit="javascript:return validateForm(this);">
<input type="text" name="username" placeholder="Firstname Lastname"/>
<span class="user-name">Name should not be empty</span>
<input type="password" name="password" placeholder="Password"/>
<input type="password" name="password1" placeholder="Confirm password"/>
<span class="password">Password does not be match</span>
<input type="email" name="email" placeholder="Email"/>
<span class="email">Email is not valid</span>
<input type="url" name="url" placeholder="Website"/>
<span class="urlcontent">Invalid Website URL</span>
<input name="submit" type="submit" value="Submit"/>
</form></div> </div>
<script type="text/javascript">
var browserName;
window.onload = function(){
document.getElementsByName("username")[0].value="";
document.getElementsByName("password")[0].value="";
document.getElementsByName("password1")[0].value="";
document.getElementsByName("email")[0].value="";
document.getElementsByName("url")[0].value="";
document.getElementById("FormSubmit").style.display="none";
document.querySelector('span[class="user-name"]').style.display="none";
document.querySelector('span[class="password"]').style.display="none";
document.querySelector('span[class="urlcontent"]').style.display="none";
document.querySelector('span[class="email"]').style.display="none";
document.getElementsByName("username")[0].focus();
browserName = navigator.appName;
//alert(browserName);
}
function validateEmail(email) {
var re = /^(([^<>()[']''.,;:'s@'"]+('.[^<>()[']''.,;:'s@'"]+)*)|('".+'"))@(('[[0-9]{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'.[0-9]{1,3}'])|(([a-zA-Z'-0-9]+'.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validateURL(curUrl){
alert("Hey, ULLLL");
var re = /^(http:'/'/www'.|https:'/'/www'.|http:'/'/|https:'/'/)[a-z0-9]+(['-'.]{1}[a-z0-9]+)*'.[a-z]{2,5}(:[0-9]{1,5})?('/.*)?$/;
return re.test(curUrl);
}
function validateForm(form) {
var returnValue=true;
if(loginForm.username.value.length < 6){
returnValue = false;
document.querySelector('span[class="user-name"]').style.display="";
loginForm.username.value = "";
loginForm.username.focus();
return returnValue;
}
if (loginForm.password.value.length < 6){
returnValue = false;
alert("Your password must be at least'n6 characters long.'n Please try again.");
loginForm.password.value = "";
loginForm.password1.value = "";
loginForm.password.focus();
return returnValue;
}
if (loginForm.password.value != loginForm.password1.value){
returnValue = false;
document.querySelector('span[class="password"]').style.display="";
loginForm.password.value = "";
loginForm.password1.value = "";
loginForm.password1.focus();
return returnValue;
}
if (loginForm.url.value.length == 0){
returnValue = false;
document.querySelector('span[class="urlcontent"]').style.display="";
loginForm.url.focus();
return returnValue;
}
if ((loginForm.email.value.length != 0) && (browserName == "Microsoft Internet Explorer")){
returnValue = false;
var imEmail = validateEmail(loginForm.email.value);
returnValue = imEmail;
if (returnValue == false) document.querySelector('span[class="email"]').style.display="";
loginForm.email.focus();
return returnValue;
}
if ((loginForm.url.value.length != 0) && (browserName == "Microsoft Internet Explorer")){
//alert("Yessssssss!");
returnValue = false;
var imURL = validateURL(loginForm.url.value);
returnValue = imURL;
if (returnValue == false) document.querySelector('span[class="urlcontent"]').style.display="";
loginForm.url.focus();//alert(returnValue);
return returnValue;
}
if(returnValue!=false) {
document.getElementById("FormSubmit").style.display="";
return false;
}
}
</script>
</body>
</html>
在IE中,它返回在这里:
if ((loginForm.email.value.length != 0) && (browserName == "Microsoft Internet Explorer")){
returnValue = false;
var imEmail = validateEmail(loginForm.email.value);
returnValue = imEmail;
if (returnValue == false) document.querySelector('span[class="email"]').style.display="";
loginForm.email.focus();
return returnValue;
^^^^^^^^^^^^^^^^^^^
}
其中if
语句实际上是这样的:
if (returnValue == false) {document.querySelector('span[class="email"]').style.display="";}
^ ^
loginForm.email.focus();
return returnValue;
我想你想要的是当它是假的时返回。你真的应该用大括号包装if
语句,否则只有第一个语句在检查下
if (returnValue == false) {
document.querySelector('span[class="email"]').style.display="";
loginForm.email.focus();
return returnValue;
}
与"loginForm.url"相同
您可以添加以下 JavaScript:
(function () {
var
style = document.createStyleSheet(),
select = function (selector, maxCount) {
var
all = document.all,
l = all.length,
i,
resultSet = [];
style.addRule(selector, "foo:bar");
for (i = 0; i < l; i += 1) {
if (all[i].currentStyle.foo === "bar") {
resultSet.push(all[i]);
if (resultSet.length > maxCount) {
break;
}
}
}
style.removeRule(0);
return resultSet;
};
// be rly sure not to destroy a thing!
if (document.querySelectorAll || document.querySelector) {
return;
}
document.querySelectorAll = function (selector) {
return select(selector, Infinity);
};
document.querySelector = function (selector) {
return select(selector, 1)[0] || null;
};
}());
我试过了,它有效。在以下位置找到链接:https://gist.github.com/Fusselwurm/4673695
相关文章:
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- PHP中的setcookie仅适用于localhost
- html5 drawImage适用于firefox,而不是chrome
- 提供“;onClick"适用于iPad(触摸屏)和桌面用户的默认功能
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- ResolveUrl是否适用于././也
- Firebase updateChildValues适用于IOS,但不适用于Web和Android
- JavaScript警报适用于int,但不适用于string
- SQLite插件适用于Mac和Windows,但不适用于手机上的Safari
- Regex Replace仅适用于Last Match
- window.onload适用于aspx页面,但不适用于普通html
- Jquery Ajax POST不工作.适用于GET
- 画布上的自定义字体仅适用于safari
- Javascript仅适用于alert()和Debug模式
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- Regex不适用于Firefox,但适用于Chrome
- 通过单击主菜单外部关闭子菜单'不适用于IE,但适用于Firefox&铬
- AngularJS$http.post没有'不适用于Chrome,仅适用于IE
- Javascript仅适用于jQuery mobile中的页面刷新
- 关闭当前选项卡并打开一个新的-仅适用于Chrome