我想創建一個懸停效果,所以當用戶將他的鼠標移動到一個按鈕上時,textarea將顯示在按鈕下方,用戶可以在提交表單之前插入文本。如果用戶在打開textarea後離開,我希望它再次關閉....下面我使用的代碼的問題是,一旦用戶離開按鈕區域(爲了插入文本textarea)textarea消失。幫助將不勝感激!ontover效果與textarea
我用下面的代碼(您也可以在jsbin找到下面的例子):
CSS
#send-container {
position:relative;
}
#text-container {
display:none;
background-color:#FEF9F4;
position: absolute;
z-index: 1000;
top:28px;
left:0;
padding:2px;
}
textarea {
width: 150px;
height: 50px;
resize: none;
border: 3px solid #cccccc;
padding: 5px;
font-family: Tahoma, sans-serif;
}
HTML
<div id="send-container">
<input type="button" value="Button">
<div id="text-container">
<textarea></textarea>
</div>
</div>
JS(jQuery的)
$("#send-container").live("mouseenter",
function() {
$("#text-container" , $(this)).show();
});
$("#send-container").live("mouseleave",
function() {
$("#text-container" , $(this)).hide();
}
);
謝謝!
Joel