input 박스 focus 시 바로 아래 div 보이게 하기

2015. 3. 24. 12:33IT/Jquery Plugin/Tip

<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>test</title>
</head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js "></script>
<!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->

<body topmargin="0" leftmargin="0" >
.example{
 background: gray;   
}​
</style>
<p>
<label for="example">Text:</label>
<input id="example" name="example" type="text" maxlength="100" />
    <div class="example">
        Some text...<br /><input type="checkbox" name="foobar" value="1" /><br />More text...
    </div>
</p>
<p>
<label for="example2">Text2:</label>
<input id="example2" name="example2" type="text" maxlength="100" />
</p>

<script>

$(document).ready(function() {
var fieldExample = $('#example');
$('div.example').css({
"position":"absolute",
"left": fieldExample.offset().left,
"top": fieldExample.offset().top + fieldExample.outerHeight()
});

fieldExample.focus(function() {
var div = $('div.example').show();
$(document).bind('focusin.example click.example',function(e) {
if ($(e.target).closest('.example, #example').length) return;
$(document).unbind('.example');
div.fadeOut('medium');
});
});
$('div.example').hide();
});
</script>


</body>
</html>