<style>input {color: gray;outline: none;}</style></head><body><input type="text" value="请输入内容" id="txt"><script src="learn2.js"></script><script>//注册获取焦点的事件my$("txt").onfocus = function () {//判断文本框是否为默认的内容if (this.value = "请输入内容") {//清空文本框this.value = "";//重新设置字体颜色this.style.color = "black";}};//注册失去焦点的事件my$("txt").onblur = function () {//判断文本框是否有内容if (this.value.length == 0) {this.value = "请输入内容";this.style.color = "gray";}};</script></body>
如果觉得《获取焦点失去焦点事件》对你有帮助,请点赞、收藏,并留下你的观点哦!