Sim*_*mon 5 html javascript css
我有一个输入文本字段,默认情况下值为"某事",但是当我开始输入时,我希望默认值改变颜色,然后我将键入另一个文本.
我怎样才能做到这一点?
<input type="text" value="something" onclick="this.value=''" />
Run Code Online (Sandbox Code Playgroud)
小智 14
为了让它像你的例子一样简单:
<input type="text" value="something" onclick="this.value='';this.style.color='red';" />
Run Code Online (Sandbox Code Playgroud)
这应该是这样做的.
您可能想尝试以下方法:
<input type="text" value="something"
onFocus="if (this.value == 'something') this.style.color = '#ccc';"
onKeyDown="if (this.value == 'something') {
this.value = ''; this.style.color = '#000'; }">
Run Code Online (Sandbox Code Playgroud)