站长资源网络编程 textarea焦点的用法实现获取焦点清空失去焦点提示效果 整理:jimmy2026/9/3浏览2次 站长资源 网络编程 网盘链接 云盘下载 简介效果图: 具体实现: 1、textarea标签内容 复制代码 代码如下: 备注: 效果图: 具体实现: 1、textarea标签内容 复制代码 代码如下: <span style="font-size:14px;"><tr> <td align="right" valign="top">备注:</td> <td><textarea name="" id="remark" cols="" rows="" class="textarea220" onfocus="this.className='textarea220L';this.onmouseout='';getAddFocus('remark');" onblur="this.className='textarea220';this.onmouseout=function(){this.className='textarea220'};lostAddFocus('remark');" onmousemove="this.className='textarea220Lg'" onmouseout="this.className='textarea220'"></textarea></td> </tr></span> 2、初始化使点击添加按钮时,内容显示最多能输入50个字 复制代码 代码如下: <span style="font-size:14px;">$("#introduction").val("最多能输入50个字"); document.getElementById("introduction").style.color="gray";</span> 3、js脚本 复制代码 代码如下: <span style="font-size:14px;">function getAddFocus(id){//针对添加操作中的简介和备注,textarea获得焦点清空输入框 var textarea=document.getElementById(id); textarea.value=""; textarea.style.color="black"; } function lostAddFocus(id){//针对添加操作中的简介和备注,textarea失去焦点且内容为空时,显示提示信息 var textarea=document.getElementById(id); var textarea_value=textarea.value; if(textarea_value==""){ textarea.value="最多能输入50个字"; textarea.style.color="gray"; } }</span> csdn小伙伴写的textarea焦点的用法参考: 复制代码 代码如下: <span style="font-size:14px;"> 1.文本框显示默认文字: <textarea>白鸽男孩</textarea> <textarea>白鸽男孩</textarea> 2.鼠标点击文本框,默认文字消失: <textarea onfocus=”if(value=='白鸽男孩') {value=' ‘}”>白鸽男孩</textarea> <textarea onfocus=”if(value=='白鸽男孩') {value=' ‘}”>白鸽男孩</textarea> 3.鼠标移至文本框,默认文字消失: <textarea onmouseover=”focus()” onfocus=”if(value=='白鸽男孩') {value=' ‘}”>白鸽男孩</textarea> <textarea onmouseover=”focus()” onfocus=”if(value=='白鸽男孩') {value=' ‘}”>白鸽男孩</textarea> 4.鼠标点击文本框,默认文字消失,点击文本框外任意区域,默认文字又重现: <textarea onfocus=”if(value=='白鸽男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鸽男孩'}”>白鸽男孩</textarea> <textarea onfocus=”if(value=='白鸽男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鸽男孩'}”>白鸽男孩</textarea> 5.鼠标移至文本框,默认文字消失,鼠标移出文本框,默认文字又重现: <textarea onmouseover=”focus()” onfocus=”if(value=='白鸽男孩') {value=' ‘}” onmouseout=”blur()” onblur=”if (value==' ‘) {value='白鸽男孩'}”>白鸽男孩</textarea> <textarea onmouseover=”focus()” onfocus=”if(value=='白鸽男孩') {value=' ‘}” onmouseout=”blur()” onblur=”if (value==' ‘) {value='白鸽男孩'}”>白鸽男孩</textarea> 6.鼠标单击文本框,文本框内任何文字消失(包括默认文字及后来输入的文字): <textarea onclick=”value=' ‘”>白鸽男孩</textarea> <textarea onclick=”value=' ‘”>白鸽男孩</textarea> 7.鼠标移至文本框,文本框内任何文字消失(包括默认文字及后来输入的文字): <textarea onmouseover=”value=' ‘”>白鸽男孩</textarea> <textarea onmouseover=”value=' ‘”>白鸽男孩</textarea> 8.单击文本框后全选文本框内的文字: <textarea onfocus=”select()”>白鸽男孩</textarea> <textarea onfocus=”select()”>白鸽男孩</textarea> 9.鼠标移至文本框全选文本框内的文字: <textarea onmouseover=”focus()” onfocus=”select()”>白鸽男孩</textarea> <textarea onmouseover=”focus()” onfocus=”select()”>白鸽男孩</textarea> 10.回车后焦点从当前文本框转移到下一个文本框: <textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鸽男孩</textarea> <textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鸽男孩</textarea> 11.回车后焦点从当前文本框转移到指定位置: <textarea onkeypress=”return focusNext(this,'指定位置的id名称',event)”>白鸽男孩</textarea> </span> 上一篇:JQuery弹出层示例可自定义 下一篇:js跨域访问示例(客户端/服务端) 最新资源 群星《奔赴!万人现场 第2期》[FLAC/分轨][518.8 群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[32 群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[FL 【古典音乐】詹姆斯·高威《季节》1993[WAV+CUE] 贝拉芳蒂《卡里普索之王》SACD[WAV+CUE] 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE] 群星《欢迎来到我身边 电影原声专辑》[320K/MP3 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓 群星《2024好听新歌42》AI调整音效【WAV分轨】 一句话新闻高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。 标签云1080P高清(5)高清电影(5)百度云盘(5)网盘下载(4)破解软件(4)绿色软件(4)磁力链接(3)强度天梯(3)福利资源(2)王者荣耀(2)黑钻活动(2)WPS会员(2)刷图排行(1)网盘限速(1)鬼灭之刃(1)免费韩国漫画(1)宫本重做(1)免费动漫(1)