js input清空输入值并还原默认值

时间:2024-02-15 14:04:35

<script type="text/javascript">
function clearDefaultText(el, message) {
var obj = el;
if (typeof(el) == "string") obj = document.getElementById(id);
if (obj.value == message) {
obj.value = "";
}
obj.onblur = function() {
if (obj.value == "") {
obj.value = message;
}
}
}
</script>

<input type="text" value="验证码" onclick="clearDefaultText(this,\'验证码\')" />