개발
[jquery] 동적으로 변경된 html 값 가져오기.
세모리a
2014. 10. 12. 08:21
스냅백같은 기능을 이용하거나 원래 내용으로 돌릴려고 할때,
jquery를 이용하여 변경한 값에 경우
<input type="text" id="test">
<script>
$("#test").val("test");
alert($("#test").html());
</script>
결과
<input type="text" id="test">
변경한 값까지 적용된 html을 가져오고 싶을땐 아래와 같이 선언한 후 가져오면 변경된 값을 가져오게 된다.
$('[type=text], textarea').each(function(){ this.defaultValue = this.value; }); $('[type=checkbox], [type=radio]').each(function(){ this.defaultChecked = this.checked; });
$('select option').each(function(){ this.defaultSelected = this.selected; });
<input type="text" id="test">
<script>
$("#test").val("test");
$('[type=text], textarea').each(function(){ this.defaultValue = this.value; });
alert($("#test").html());
</script>
결과
<input type="text" id="test" value="test">