2011-08-10 4 views
1

에서 나는 다음과 같은 코드가 있습니다.jQuery를 onchange를 이벤트가 발생 두 번 IE8

하지만 내가 "this.value = jQuery.trim (this.value);"행에 주석을 달면 " 메시지는 한 번만 표시됩니다.

왜 이런 일이 일어 났습니까? 그리고 두 번 "onchange"핸들러 호출을 피할 수있는 방법은 무엇입니까?

답변

2

양식 요소의 value 속성을 다른 값으로 설정하면 change 이벤트가 발생합니다.

그래서, 코드에서 :

$('#test').change(function() { 
    // This is executed whenever the `change` event fires 
    // Setting a new value will trigger the `change` event again 
    this.value = $.trim(this.value); 
}); 

그런데, 당신은 아마 the input event 대신 change을 사용하고 싶습니다. 그에 대한 jQuery 플러그인이 있습니다 : https://github.com/mathiasbynens/jquery.oninput.js

+0

하지만 Chrome 13에서는 FF4 onchange 이벤트가 한 번만 발생합니다. – maxvasil

+2

@vasmt 그게 크로스 브라우저 스크립팅이야! –

3

Issue은 jQuery에서보고되었으며 최신 코드베이스로 수정되었습니다. jQuery 1.4 - 1.6.4에서보고되었습니다.

관련 문제