我有這個發揮各地根據@ strager的建議和由以下,優異的功能代碼
的jQuery:
$(":text[value='']").addClass('empty');
$(":text[value>='']").removeClass('empty');
$('.ez-edit').blur(function() {
if ($(this).val().length >= 0) {
$(this).removeClass('empty');
}
if ($(this).val().length <= 0) {
$(this).addClass('empty');
}
});
和CSS:
input.ez-edit {
font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, Verdana, sans-serif;
font-weight:bold;
display: inline;
padding:5px 8px 5px 2px;
background-color: transparent;
border-style: none;
border-top: 1px solid #cdcdcd;
color: inherit;
font-size: inherit;
}
input.ez-edit:hover {
text-decoration: underline;
/* following "pencil" img from: http://enon.in/6j */
background:url(../images/pencil.gif) no-repeat right #ffffdc;
border-style:1px hidden;
border-top:1px solid #fff;
border-right-color:#fff;
border-bottom-color:#fff;
border-left-color:#fff;
}
input.ez-edit:focus, input.ez-edit:focus:hover {
display:inline-block;
border:1px solid #4d4d4d;
font-size:12px;
background-color:#FFFFDc;
color:#333;
font-weight:normal;
}
就像你說的,缺點是固定寬度,這是我認爲DOM開關的主要原因之一。另外,如果文本輸入有很多文本,如果背景隱藏,它將如何操作。我會試一試,看看這個建議在我的情況下是否可行。謝謝。 – 2010-03-10 02:01:07