원하는 것을 입력 할 수있는 빈 입력 상자가 있습니다. 마우스를 입력 위에 놓으면 입력 상자에있는 텍스트로 제목이 표시됩니다.
<input type="text" />
$(document).ready(function() {
$('input').mouseover(function() {
var $txt = $('input').text();
$('input').attr('title', $txt);
})
})
사용하여
keyup
업데이트하는 이벤트를title
속성. Alex가 언급했듯이this
in을 사용handler
하면current
입력 요소 의 값을 읽고 입력 요소의title
속성을 업데이트 합니다current
.$('input')
모든input
태그 요소 를 선택 하고 일치하는 모든 요소에 대해.attr()
설정attribute
합니다.
또한 .val()
입력에서 값을 가져 오는 데 사용해야 합니다.text()
이 시도:
$(document).ready(function() {
$('input').keyup(function() {
var $txt = $(this).val();
$(this).attr('title', $txt);
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" />
편집 : 또는 사용은 input
, 의 값 때 이벤트가 동 기적으로 해고 <input>
또는 <textarea>
요소가 변경됩니다. 이벤트가 호출 되기 전에 설정 .trigger('input')
되었는지 확인하기 위해 사용하십시오 .title
initially
input
이 시도:
$(document).ready(function() {
$('input').on('input', function() {
var $txt = $(this).val();
$(this).attr('title', $txt);
});
$('input').trigger('input');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" value='Hello' />
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다