<body><input type="text" value = "请输入员工号"onfocus='if(this.value==defaultValue){this.value=""}'onblur=" if(this.value==''){this.value=defaultValue}"/><script type="text/jscript"></script> </body></html>怎么把这个功能改成函数形式
3 回答
千秋此意
TA贡献158条经验 获得超187个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script> function focusHandler(el) { if (el.value === el.defaultValue) { el.value = ''; } } function blurHandler(el) { if (el.value === '') { el.value = el.defaultValue; } } </script> </head> <body> <input type="text" value="请输入员工号" onfocus="focusHandler(this)" onblur="blurHandler(this)"> </body> </html>
添加回答
举报
0/150
提交
取消