我可以使用以下代码实现当输入框获得/失去焦点时,显示/隐藏一个隐藏的
$('#example').focus(function() {
$('div.example').css('display','block');
}).blur(function() {
$('div.example').fadeOut('medium');
});
问题是我想要<p>
<label for="example">Text:</label>
<input id="example" name="example" type="text" maxlength="100" />
<div class="example">Some text...<br /><br />More text...</div>
</p>
当用户单击输入框和/或div.example
外部时,我如何使div.example
消失? 我尝试使用focusin / focusout来检查<p>
的焦点,但也不起作用。
div.example
是否直接通过jQuery位于输入字段#example下方? 做这件事的代码如下:
var fieldExample = $('#example');
$('div.example').css("position","absolute");
$('div.example').css("left", fieldExample.offset().left);
$('div.example').css("top", fieldExample.offset().top + fieldExample.outerHeight());
如果这个问题之前已经被问过,请原谅我,但是我所看到的众多显示/隐藏div的问题并没有涵盖这个。感谢您的建议。:)