textarea焦點(diǎn)的用法實(shí)現(xiàn)獲取焦點(diǎn)清空失去焦點(diǎn)提示效果
更新時(shí)間:2014年05月19日 17:10:57 作者:
這篇文章主要介紹了textarea焦點(diǎn)的用法實(shí)現(xiàn)獲取焦點(diǎn)清空失去焦點(diǎn)提示效果,需要的朋友可以參考下
效果圖:

具體實(shí)現(xiàn):
1、textarea標(biāo)簽內(nèi)容
<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、初始化使點(diǎn)擊添加按鈕時(shí),內(nèi)容顯示最多能輸入50個(gè)字
<span style="font-size:14px;">$("#introduction").val("最多能輸入50個(gè)字");
document.getElementById("introduction").style.color="gray";</span>
3、js腳本
<span style="font-size:14px;">function getAddFocus(id){//針對(duì)添加操作中的簡(jiǎn)介和備注,textarea獲得焦點(diǎn)清空輸入框
var textarea=document.getElementById(id);
textarea.value="";
textarea.style.color="black";
}
function lostAddFocus(id){//針對(duì)添加操作中的簡(jiǎn)介和備注,textarea失去焦點(diǎn)且內(nèi)容為空時(shí),顯示提示信息
var textarea=document.getElementById(id);
var textarea_value=textarea.value;
if(textarea_value==""){
textarea.value="最多能輸入50個(gè)字";
textarea.style.color="gray";
}
}</span>
csdn小伙伴寫的textarea焦點(diǎn)的用法參考:
<span style="font-size:14px;"> 1.文本框顯示默認(rèn)文字:
<textarea>白鴿男孩</textarea>
<textarea>白鴿男孩</textarea>
2.鼠標(biāo)點(diǎn)擊文本框,默認(rèn)文字消失:
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
3.鼠標(biāo)移至文本框,默認(rèn)文字消失:
<textarea onmouseover=”focus()” onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
<textarea onmouseover=”focus()” onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
4.鼠標(biāo)點(diǎn)擊文本框,默認(rèn)文字消失,點(diǎn)擊文本框外任意區(qū)域,默認(rèn)文字又重現(xiàn):
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鴿男孩'}”>白鴿男孩</textarea>
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鴿男孩'}”>白鴿男孩</textarea>
5.鼠標(biāo)移至文本框,默認(rèn)文字消失,鼠標(biāo)移出文本框,默認(rèn)文字又重現(xiàn):
<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.鼠標(biāo)單擊文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來(lái)輸入的文字):
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
7.鼠標(biāo)移至文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來(lái)輸入的文字):
<textarea onmouseover=”value=' ‘”>白鴿男孩</textarea>
<textarea onmouseover=”value=' ‘”>白鴿男孩</textarea>
8.單擊文本框后全選文本框內(nèi)的文字:
<textarea onfocus=”select()”>白鴿男孩</textarea>
<textarea onfocus=”select()”>白鴿男孩</textarea>
9.鼠標(biāo)移至文本框全選文本框內(nèi)的文字:
<textarea onmouseover=”focus()” onfocus=”select()”>白鴿男孩</textarea>
<textarea onmouseover=”focus()” onfocus=”select()”>白鴿男孩</textarea>
10.回車后焦點(diǎn)從當(dāng)前文本框轉(zhuǎn)移到下一個(gè)文本框:
<textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鴿男孩</textarea>
<textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鴿男孩</textarea>
11.回車后焦點(diǎn)從當(dāng)前文本框轉(zhuǎn)移到指定位置:
<textarea onkeypress=”return focusNext(this,'指定位置的id名稱',event)”>白鴿男孩</textarea> </span>

具體實(shí)現(xiàn):
1、textarea標(biāo)簽內(nèi)容
復(fù)制代碼 代碼如下:
<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、初始化使點(diǎn)擊添加按鈕時(shí),內(nèi)容顯示最多能輸入50個(gè)字
復(fù)制代碼 代碼如下:
<span style="font-size:14px;">$("#introduction").val("最多能輸入50個(gè)字");
document.getElementById("introduction").style.color="gray";</span>
3、js腳本
復(fù)制代碼 代碼如下:
<span style="font-size:14px;">function getAddFocus(id){//針對(duì)添加操作中的簡(jiǎn)介和備注,textarea獲得焦點(diǎn)清空輸入框
var textarea=document.getElementById(id);
textarea.value="";
textarea.style.color="black";
}
function lostAddFocus(id){//針對(duì)添加操作中的簡(jiǎn)介和備注,textarea失去焦點(diǎn)且內(nèi)容為空時(shí),顯示提示信息
var textarea=document.getElementById(id);
var textarea_value=textarea.value;
if(textarea_value==""){
textarea.value="最多能輸入50個(gè)字";
textarea.style.color="gray";
}
}</span>
csdn小伙伴寫的textarea焦點(diǎn)的用法參考:
復(fù)制代碼 代碼如下:
<span style="font-size:14px;"> 1.文本框顯示默認(rèn)文字:
<textarea>白鴿男孩</textarea>
<textarea>白鴿男孩</textarea>
2.鼠標(biāo)點(diǎn)擊文本框,默認(rèn)文字消失:
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
3.鼠標(biāo)移至文本框,默認(rèn)文字消失:
<textarea onmouseover=”focus()” onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
<textarea onmouseover=”focus()” onfocus=”if(value=='白鴿男孩') {value=' ‘}”>白鴿男孩</textarea>
4.鼠標(biāo)點(diǎn)擊文本框,默認(rèn)文字消失,點(diǎn)擊文本框外任意區(qū)域,默認(rèn)文字又重現(xiàn):
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鴿男孩'}”>白鴿男孩</textarea>
<textarea onfocus=”if(value=='白鴿男孩') {value=' ‘}” onblur=”if(value==' ‘) {value='白鴿男孩'}”>白鴿男孩</textarea>
5.鼠標(biāo)移至文本框,默認(rèn)文字消失,鼠標(biāo)移出文本框,默認(rèn)文字又重現(xiàn):
<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.鼠標(biāo)單擊文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來(lái)輸入的文字):
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
7.鼠標(biāo)移至文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來(lái)輸入的文字):
<textarea onmouseover=”value=' ‘”>白鴿男孩</textarea>
<textarea onmouseover=”value=' ‘”>白鴿男孩</textarea>
8.單擊文本框后全選文本框內(nèi)的文字:
<textarea onfocus=”select()”>白鴿男孩</textarea>
<textarea onfocus=”select()”>白鴿男孩</textarea>
9.鼠標(biāo)移至文本框全選文本框內(nèi)的文字:
<textarea onmouseover=”focus()” onfocus=”select()”>白鴿男孩</textarea>
<textarea onmouseover=”focus()” onfocus=”select()”>白鴿男孩</textarea>
10.回車后焦點(diǎn)從當(dāng)前文本框轉(zhuǎn)移到下一個(gè)文本框:
<textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鴿男孩</textarea>
<textarea onkeydown=”if(event.keyCode==13)event.keyCode=9″>白鴿男孩</textarea>
11.回車后焦點(diǎn)從當(dāng)前文本框轉(zhuǎn)移到指定位置:
<textarea onkeypress=”return focusNext(this,'指定位置的id名稱',event)”>白鴿男孩</textarea> </span>
相關(guān)文章
跨域?yàn)g覽器設(shè)置解決前端跨域問(wèn)題
這篇文章主要為大家介紹了前端跨域?yàn)g覽器設(shè)置解決前端跨域問(wèn)題的方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
移動(dòng)端圖片上傳旋轉(zhuǎn)、壓縮問(wèn)題的方法
在本篇文章中我們給大家分享了關(guān)于移動(dòng)端圖片上傳旋轉(zhuǎn)、壓縮問(wèn)題的解決方法,有需要的朋友們參考下2018-10-10
javascript實(shí)現(xiàn)Table間隔色以及選擇高亮(和動(dòng)態(tài)切換數(shù)據(jù))的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)Table間隔色以及選擇高亮(和動(dòng)態(tài)切換數(shù)據(jù))的方法,涉及javascript表格操作及按鈕實(shí)現(xiàn)表格切換的技巧,需要的朋友可以參考下2015-05-05
JS實(shí)現(xiàn)判斷移動(dòng)端PC端功能
這篇文章主要介紹了JS實(shí)現(xiàn)判斷移動(dòng)端PC端功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02
JS實(shí)現(xiàn)點(diǎn)擊網(wǎng)頁(yè)判斷是否安裝app并打開(kāi)否則跳轉(zhuǎn)app store
這篇文章主要介紹了JS實(shí)現(xiàn)點(diǎn)擊網(wǎng)頁(yè)判斷是否安裝app并打開(kāi)否則跳轉(zhuǎn)app store的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11

