2011-07-29 3 views
0
0에서 다른 수량에있을 때 내가 onbeforeunload하는 예외와 데이터를 잃어버린에 대한 경고를 만들기 위해 노력하고

:이 시도Onbeforeunload 예외

:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title></title> 

<script src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 

<body> 
<form> 
<p><input type="text" value="0" maxlength="12" id="qty" class="input-text qty" name="qty2603"></p> 
<p><input type="text" value="0" maxlength="12" id="qty" class="input-text qty" name="qty2613"></p> 
<p><input type="text" value="0" maxlength="12" id="qty" class="input-text qty" name="qty2606"></p> 


<p><a href="http://www.google.com">Google</a></p> 
<p> 
    <input type="submit" name="Submit" value="Envoyer" onclick="prompt = false;" /> 


</p> 
</form> 

<script type="text/javascript"> 
$(window).bind('beforeunload', function(e) { 
    var prompt = true; 
    $('input.qty').each(function(i, input) { 
     if ($(input).val() != '0') { 
      prompt = true; 
     } 
    }); 

    if (prompt) { 
     return e.returnValue = 'Some warning message'; 
    } 
}); 
</script> 

</body> 
</html> 

하지만이 같은 작동하지 않습니다는 나는 ...

아무도 도와 줄 수 있습니까?

고마워요.

답변

0

prompt입니다. 항상입니다. 기본적으로, 그리고 0과 다른 경우입니다.

var prompt = false; // set to false by default 

$('input.qty').each(function(i, input) { 
    if ($(input).val() != '0') { 
     prompt = true; 
    } 
}); 

if (prompt) { 
    return e.returnValue = 'Some warning message'; 
} 
+0

작동하지 않는 :( – Bizboss

+0

는 @Bizboss : 그것은 작동하지 않는 방법, 그리고 당신이 원하는 게 무엇은 할 적절한 때 기본적으로 false로

설정을 대신하고, true로 변경 ? – pimvdb

+0

귀하의 편집과 함께, 내가 링크를 클릭하면 페이지를 종료 할 수 없어 그 페이지를 종료 할 수있는 페이지를 종료 할 수 있습니다, 스크립트는 경고 메시지를 표시해야 하나 이상의 텍스트 필드 ... 이제는 더 명확 해집니다. 고마워요 :) – Bizboss