我总是做输入提示,像这样:
οnfοcus="this.value=''; this.style.color='#000000'">
当然,如果您的用户填写该字段,更改焦点并返回该字段,则该字段将再次被清除。 如果您那样做,请确保这就是您想要的。您可以通过设置信号量来使其成为一次性的事情,如下所示:
cleared[0] = cleared[1] = cleared[2] = 0; //set a cleared flag for each field
function clearField(t){ //declaring the array outside of the
if(! cleared[t.id]){ // function makes it static and global
cleared[t.id] = 1; // you could use true and false, but that's more typing
t.value=''; // with more chance of typos
t.style.color='#000000';
}
}
您的字段如下所示:
οnfοcus=clearField(this)>