javascript搜尋方塊點擊文字消失失焦時文本出現,javascript焦時

來源:互聯網
上載者:User

javascript搜尋方塊點擊文字消失失焦時文本出現,javascript焦時

當獲焦時,文本消失,失焦時文本出現

<!doctype html><html><head><meta charset="utf-8"><title>無標題文檔</title></head><body><input id="text" type="text" value="點我就消失"/><script>var oText=document.getElementById("text");var onoff=true;oText.color="#000";oText.onfocus=function(){if(onoff){this.value="";this.color="red";onoff=false;}}oText.onblur=function(){if(this.value==''){this.color="#000";this.value="點我就消失";onoff=true;}}</script></body></html>


怎在javaScript裡面設定彈出一個層,點擊文字框時層出現,選擇層裡面的值,選擇後曾自動關閉

<input type="text" id="tbText" onfocus="javascript:document.getElementById('divValue').style.display='block';" />
<div id="divValue" style="display:none;">
<a href="javascript:void(0);" onclick="javascript:setValue(this);">值一</a><br>
<a href="javascript:void(0);" onclick="javascript:setValue(this);">值二</a><br>
<a href="javascript:void(0);" onclick="javascript:setValue(this);">值三</a><br>
<a href="javascript:void(0);" onclick="javascript:setValue(this);">值四</a><br>
</div>
<script language="javascript">
function setValue(obj)
{
document.getElementById('tbText').value=obj.innerHTML;
document.getElementById('divValue').style.display='none';
}
</script>
 
javascript裡怎聚焦到文字框文字後面去?

<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">

srcElement是ie的屬性 要考慮相容
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.