没有什么特别简单的事情浮现在我的脑海里。
我的替代方法是将默认输入值分别设置为“客户名称”和“项目名称”。使用少量 JavaScript,您可以在用户获得焦点时自动清除输入。如果在用户模糊输入时输入为空,则额外的洒水将用“客户名称”和“项目名称”重新填充输入。
警告:我对 JavaScript 及其跨浏览器兼容性问题知之甚少。例如,我认为getElementsByClassName
在某些版本的 IE 中是没有实现的。以这段代码为例,而不是生产代码。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Inline form</title>
<script type="text/javascript">
var valueHints = []
window.onload = function() {
var inputs = document.getElementsByClassName("value-hint");
for (var i = 0; i < inputs.length; ++i) {
valueHints[inputs[i].id] = inputs[i].value;
inputs[i].onfocus = function() {
if (valueHints[this.id] == this.value) {
this.value = "";
}
}
inputs[i].onblur = function() {
if (this.value == "") {
this.value = valueHints[this.id];
}
}
}
}
</script>
<style type="text/css">
.value-hint {
color:#999999;
}
</style>
</head>
<body>
<p>Hello <input class="value-hint" id="customer" type="text" value="Customer Name"></span>, This is to inform you that the <input class="value-hint" id="item" type="text" value="Item Name"> you ordered is no longer available.</p>
</body>
</html>