두 경우에 함수를 실행해야합니다. 페이지가로드 될 때마다 하나씩, 요소가 클릭 될 때마다 하나씩 함수를 실행해야합니다. click 이벤트는 작동하지만 onload 이벤트는 작동하지 않습니다.여러 이벤트에서 함수 실행
$(document).ready(function(e) {
var captcha;
$('#captcha').on('ready click',function(){
function alphanumeric_unique() {
return Math.random().toString(36).split('').filter(function(value, index, self) {
return self.indexOf(value) === index;
}).join('').substr(2,8);
}
captcha = alphanumeric_unique();
$(this).val(captcha);
});
});
<input type="text" readonly value="" id="captcha">
어떤 도움을 주시겠습니까?
함수로합니다. 그런 다음 load에 함수를 호출하고이를 이벤트 핸들러에 할당합니다. –