Clearing the textbox values onclick and displaying onblur
有没有办法清除文本框上的默认文本框值onclick并在窗体页面上显示多个文本框的onblur?
function Clear1(str)
{
document.getElementById(str).value= "";
}
function Clear2(str2)
{
var aa1=document.getElementById(str2);
if (aa1.value==""){
document.getElementById(str2).style.backgroundColor = "#ffcccc";
}else{
document.getElementById(str2).style.backgroundColor = "#ffffff";
}
}
<input type="text" value="test1" onClick="Clear1(this.id);" id="textbox1" onblur="Clear2(this.id);">
<input type="text" value="test2" onClick="Clear1(this.id);" id="textbox2" onblur="Clear2(this.id);">
<input type="text" value="test3" onClick="Clear1(this.id);" id="textbox3" onblur="Clear2(this.id);">
<input type="text" value="test4" onClick="Clear1(this.id);" id="textbox4" onblur="Clear2(this.id);">
HTML:
<input type="text" value="" onClick="Clear();" id="textbox1>
<input type="text" value="" onClick="Clear();" id="textbox2>
<input type="text" value="" onClick="Clear();" id="textbox3>
<input type="text" value="" onClick="Clear();" id="textbox4>
Javascript :
function Clear()
{
document.getElementById("textbox1").value= "";
document.getElementById("textbox2").value= "";
document.getElementById("textbox3").value= "";
document.getElementById("textbox4").value= "";
}
Your question was a little vague to me, but the above will clear all the textboxes when one is clicked. Hopefully this helps you.
One Line solution
<input type="text" value="" onClick="this.value='';" id="textbox1">
or
<input type="text" value="" onClick="this.value=='Initial Text'?this.value='':this.value;" id="textbox1">
链接地址: http://www.djcxy.com/p/70554.html