아래 코드가있는 경우 새로운 직렬 버튼을 여러 번 누르면 serial 클래스의 텍스트 상자가 이벤트에 두 번 이상 바인딩됩니다.jQuery에서 여러 번 이벤트를 바인딩하면 효과가 발생합니까?
jQuery는 바인딩 메소드가 여러 번 호출 되더라도 이벤트를 한 번만 등록합니까?
$(document).ready(function() {
MonitorSerialTextBoxes();
$('#newSerial').click(function() {
$.tmpl("productTemplate", mymodel).insertAfter($(".entry").last());
MonitorSerialTextBoxes();
});
function MonitorSerialTextBoxes() {
$('.serial').each(function() {
// Save current value of element
$(this).data('oldVal', $(this).val());
// Look for changes in the value
$(this).bind("propertychange keyup input paste", function (event) {
// If value has changed...
if ($(this).data('oldVal') != $(this).val() && $(this).val().length == 10) {
// Updated stored value
$(this).data('oldVal', $(this).val());
// Do action
}
});
}
});
UPDATE : 나는 그래서 MonitorSerialTextBoxes 기능 수정 thiings에 아래 코드를 추가 할 것으로 예상? JQuery와 문서에서
$('.serial').unbind("propertychange keyup input paste");
:
여러 핸들러 등록이있는 경우, 그들은 항상 당신은 여러 이벤트 처리기를 바인딩 할 수 있습니다
테스트하지 않고 답을 잘 모르겠지만 Visual Event로 직접 테스트 해 볼 수 있습니다. http://www.sprymedia.co.uk/article/Visual+Event 페이지의 지침을 따르십시오. –