textarea焦點(diǎn)的用法實(shí)現(xiàn)獲取焦點(diǎn)清空失去焦點(diǎn)提示效果
更新時間: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)擊添加按鈕時,內(nèi)容顯示最多能輸入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獲得焦點(diǎn)清空輸入框
var textarea=document.getElementById(id);
textarea.value="";
textarea.style.color="black";
}
function lostAddFocus(id){//針對添加操作中的簡介和備注,textarea失去焦點(diǎn)且內(nèi)容為空時,顯示提示信息
var textarea=document.getElementById(id);
var textarea_value=textarea.value;
if(textarea_value==""){
textarea.value="最多能輸入50個字";
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)文字及后來輸入的文字):
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
7.鼠標(biāo)移至文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來輸入的文字):
<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)移到下一個文本框:
<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)擊添加按鈕時,內(nèi)容顯示最多能輸入50個字
復(fù)制代碼 代碼如下:
<span style="font-size:14px;">$("#introduction").val("最多能輸入50個字");
document.getElementById("introduction").style.color="gray";</span>
3、js腳本
復(fù)制代碼 代碼如下:
<span style="font-size:14px;">function getAddFocus(id){//針對添加操作中的簡介和備注,textarea獲得焦點(diǎn)清空輸入框
var textarea=document.getElementById(id);
textarea.value="";
textarea.style.color="black";
}
function lostAddFocus(id){//針對添加操作中的簡介和備注,textarea失去焦點(diǎn)且內(nèi)容為空時,顯示提示信息
var textarea=document.getElementById(id);
var textarea_value=textarea.value;
if(textarea_value==""){
textarea.value="最多能輸入50個字";
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)文字及后來輸入的文字):
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
<textarea onclick=”value=' ‘”>白鴿男孩</textarea>
7.鼠標(biāo)移至文本框,文本框內(nèi)任何文字消失(包括默認(rèn)文字及后來輸入的文字):
<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)移到下一個文本框:
<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)文章
javascript實(shí)現(xiàn)Table間隔色以及選擇高亮(和動態(tài)切換數(shù)據(jù))的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)Table間隔色以及選擇高亮(和動態(tài)切換數(shù)據(jù))的方法,涉及javascript表格操作及按鈕實(shí)現(xiàn)表格切換的技巧,需要的朋友可以參考下2015-05-05
JS實(shí)現(xiàn)點(diǎn)擊網(wǎng)頁判斷是否安裝app并打開否則跳轉(zhuǎn)app store
這篇文章主要介紹了JS實(shí)現(xiàn)點(diǎn)擊網(wǎng)頁判斷是否安裝app并打開否則跳轉(zhuǎn)app store的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-11-11

