我正在尝试用jQuery制作动画。它在当前页面中工作,但当我在Javascript中使用window.location.href时(当x.value为true时)。
这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test jQuery</title>
<link rel="stylesheet" href="test-alert-1.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function result(){
var x = document.getElementById("name");
if (x.value){
window.location.href='http://www.google.com';
}else{
alert('This field cannot be empty');
}
}
</script>
<script>
`$`(window).load(function() {
`$`(".loader").fadeOut("1000");
})
</script>
</head>
<body>
<div class="loader"> </div>
<form action="" method="post">
<div>
<label for="name">Name :</label>
<input type="text" id="name" />
</div>
</form>
<input type="image" onclick="result();" src="../../image/loupe.png" class="loupe">
</body>
</html>和我的CSS:
.loader {
background: url(../../image/squares2.gif) no-repeat center;
cursor: wait;
height: 100%;
left: 0px;
position: fixed;
top: 0px;
width: 100%;
z-index: 9999;}发布于 2016-03-05 19:57:56
你不能fadeOut一个location.href的改变,
您可以尝试的,淡出并添加location.href作为回调
像这样的东西
function result(){
var x = document.getElementById("name");
if (x.value){
$(".loader").fadeOut(1000, function(){
window.location.href='http://www.google.com';
});
}else{
alert('This field cannot be empty');
}
}https://stackoverflow.com/questions/35813771
复制相似问题