목표 :리디렉션 후 jQuery .focus 이벤트가 배경색을 녹색으로 변경하는 이유는 무엇입니까?
가 첫 번째 입력 상자 배경 색 변화를 가지고 리디렉션 후 (target.html 자세한에) 녹색. Google 크롬에서 명시 적으로 링크 (URL 막대에 입력)로 이동하면 작동합니다.
나는 구글 크롬이 버전의 사용하고 있습니다 : 13.0.782.112
그것은이 하나 jFiddle를 사용하기는 어렵습니다을, 그래서 난 그냥 (CDN) jQuery를 파일에게 콘텐츠 전송 네트워크를 사용하여 당신에게 코드를주지 당신을 위해 더 쉽게 만들 수 있습니다.
자세한 내용은이 질문을 참조 :
Why doesn't initial page focus change input field to Green on Google Chrome?
소스 페이지 :
이 (source.html이 페이지의 이름을)
<html>
<head>
</head>
<body>
<a href="./target.html">click this hyperlink in Google Chrome and see if the background-color changes to green on the first input field on target.html</a>
</body>
</html>
대상 페이지를 :
는가
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
function Change(obj, evt) {
if (evt.type == "focus") {
$(obj).css('border-color', '#000000');
$(obj).css('background-color', '#90EE90');
}
else if (evt.type == "blur") {
$(obj).css('border-color', '#FFFFFF');
$(obj).css('background-color', '#7AC5CD');
}
}
$(document).ready(function() {
$("#Txt1").focus();
});
</script>
<style type="text/css">
.InputField
{
color: black;
font-size: 12px;
font-weight: bold;
background-color: #7AC5CD;
}
</style>
</head>
<body>
<input id="Txt1" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt2" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt3" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
</body>
</html>
Chrome의 '이상한 이유로 인해'변경됨 '안에 경고가 표시됩니다.'변경 '이 무한대로 호출됩니다 ... – Rafay
기술적으로 경고 메시지를 닫을 때 onfocus 이벤트가 입력에서 발생하기 때문에 발생합니다. –
매우 맞고 크롬에서만 발생합니다 ... – Rafay