이것에 대한 도움을 주시면 감사하겠습니다. keyup에서 동적으로 생성 된 텍스트 입력의 크기를 조정하려고합니다. 기본 수준에서이 작업을 수행 할 수 있지만 동일한 클래스를 가진 개별 입력 크기를 조정하는 데 문제가 있습니다. 즉, 하나의 개별 입력 필드 크기를 조정하는 대신 ".question"클래스가있는 모든 텍스트 입력의 크기가 조정됩니다.
내 코드는 다음과 같습니다.
function resizeInput(theInputField) {
var getInputWidth = $(theInputField).width();
if(getInputWidth < 400){
$(theInputField).attr('size', $(theInputField).val().length);
}
}
$('#question-list').on('keyup', '.question', function(){
resizeInput('.question');
});
$ ( '# question-list')-> 이것은 ul 요소입니다.
$ ( '. question')-> 위의 ul에서 동적으로 생성 된 입력 [type = "text"]입니다.
이벤트 핸들러에서 이벤트 this
를 트리거 한 요소입니다. 다음과 같이 할 수 있습니다.
function resizeInput($theInputField) {
var inputWidth = $theInputField.width();
if(inputWidth < 400){
$theInputField.attr('size', $theInputField.val().length);
}
}
$('#question-list').on('keyup', '.question', function(){
resizeInput($(this));
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다