html 文本輸入框效果

來源:互聯網
上載者:User

文本輸入框特效大集合

1、選中後方可編輯:

<input type="checkbox" name="tp1" value="1" onclick="if(this.checked){txtNo.disabled=false}else{txtNo.disabled=true}">我會好好學習
你的姓名:<input type="text" name="txtNo" size="20" value="選中前面的選項方可編輯" disabled>

 

2、點選連結後方可編輯:
<a href="#" onclick="b.readOnly=false;alert('你好,歡迎你!')">先點擊我哦!</a>
你的姓名:<input id="b" value="--請輸入--" size="30" readOnly>

 

3、輸入框從中間輸入:
從中間輸入:<input type="text" name="text2"style="text-align:center;">

 

4、輸入框變色:
輸入框變色:<input type="text" size="20" style="background-color:#FFFFFF" onfocus="style.backgroundColor='#FFFF00'"onblur="style.backgroundColor='#FFFFFF'">

 

5、輸入框只能輸入數字(用的是Regex):
你的年齡:<input onkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">

 

6、輸入框只能輸入中文(用的是Regex):
你的中文名:<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">

 

7、只能輸入英文和數字(用的是Regex):

你的暱稱:<input onkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
onkeydown="if(event.keyCode==13)event.keyCode=9">

 

8、輸入框不能編輯,但表單可以獲得輸入框內的值:
總和:<input type="text" value="160" onclick="alert('總和不能編輯!');" onfocus="this.blur()" />
總和:<input type="text" value="吳秋華" onclick="alert(this.value);" readonly />

 

9、輸入框禁止IME:

<input onpaste="return false" style="ime-mode:disabled">

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.