我试图做一个非常简单的代码,使一个文本字段具有默认的提示:当鼠标移动时,它们会消失,当鼠标离开时,它们就会出现。我知道我可以用
this.rawValue = " "
this.rawValue = "Address"将"Value“部分设置为默认的"Address”。我的问题是,当我键入某项内容时,如果我再次不小心单击该部分,它将返回到默认值。
我遗漏了什么?如果没有输入新文本,我需要它只返回默认值。
发布于 2014-12-29 17:13:11
只要更改它,它就不会编辑文本,如果用户已经输入任何内容。
在滑鼠事件中:
//if the text is the default text, hide it on mouseover.
if (this.rawValue == "Address") this.rawValue = "";在mouseExit事件中:
//if the text is empty, replace it with the default when the user exits the field.
if (this.rawValue == "" || this.rawValue == null) this.rawValue = "Address";我会考虑将其放在普通的enter/exit事件中,而不是鼠标特定的事件中,因为一些用户可能会使用选项卡键导航表单。
另外,不要使用空格来表示空,只需使用"“。
https://stackoverflow.com/questions/27611051
复制相似问题