답변:
다음 과 같이 .val()사용 하는 대신 .text():
$(".ui-datepicker-month").live("click", function () {
var monthname = $(this).text();
alert(monthname);
});
또는 jQuery를 1.7+ 사용 on()으로 live사용되지 않습니다 :
$(document).on('click', '.ui-datepicker-month', function () {
var monthname = $(this).text();
alert(monthname);
});
.val()입력 유형 요소 (텍스트 영역 및 드롭 다운 포함) 용입니다. 텍스트 콘텐츠가있는 요소를 다루기 때문에 .text()여기 에서 사용 하세요.
-위의 어느 것도 나를 위해 일관되게 효과가 없었습니다. 그래서 여기에 기본 기능을 사용하므로 모든 브라우저에서 일관되게 작동하는 솔루션이 있습니다. 이것이 다른 사람들에게 도움이되기를 바랍니다. jQuery 8.2 사용
1) "span"에 대한 jquery 객체를 가져옵니다. 2) 위에서 DOM 개체를 가져옵니다. jquery .get (0) 사용 3) DOM의 객체의 innerText를 사용하여 텍스트를 가져옵니다.
다음은 간단한 예입니다.
var curSpan = $(this).parent().children(' span').get(0);
var spansText = curSpan.innerText;
HTML
<div >
<input type='checkbox' /><span >testinput</span>
</div>
.live()1.7에서 더 이상 사용되지 않고 1.9 이상에서 제거