html中input輸入框使用總結

2022-04-08 16:41:31 字數 2954 閱讀 6168

1、選中去除文字框文字,離開後顯示原有文字:

<

input

name

="key"

type

="text"

id="key"

value

size

="30"

onmouseover

=this.focus();this.select();

onclick

="if(value==defaultvalue)"

onblur

="if(!value)"

style

="color:#999"

/>

<

input

type

="checkbox"

name

="tpbox"

value

="1"

onclick

="if(this.checked) else"

>

你的姓名:

<

input

type

="text"

name

="txtno"

size

="20"

value

="選中前面的選項方可編輯"

disabled

>

<

a href

="#"

onclick

="username.readonly=false;alert('你好,歡迎使用!')"

>先點選我哦!

a>

你的姓名:

<

input

id="username"

value

="--請輸入--"

size

="30"

readonly

>

4、輸入框從中間輸入:

<

input

type

="text"

name

="mid"

style

="text-align:center;"

>

5、輸入框變色:

<

input

type

="text"

size

="20"

style

="background-color:#ffffff"

onfocus

="style.backgroundcolor='#ffff00'"

onblur

="style.backgroundcolor='#ffffff'"

>

6、輸入框只能輸入數字(用的是正規表示式):你的年齡:

<

input

onkeyup

="value=value.replace(/[^\d]/g,'') "

onbeforepaste

="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"

>

7、輸入框只能輸入中文(用的是正規表示式):你的中文名:

<

input

onkeyup

="value=value.replace(/[ -~]/g,'')"

onkeydown

="if(event.keycode==13)event.keycode=9"

>

8、只能輸入英文和數字(用的是正規表示式):

你的暱稱:<

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"

>

<

input

type

="text"

value

="afreon"

onclick

="alert('總和不能編輯!');"

onfocus

="this.blur()"

/>

<

input

type

="text"

value

="afreon"

onclick

="alert(this.value);"

readonly

/>

<

input

value

="不可修改"

readonly

= "true"

type

="text"

/>//:字型顏色為黑體

10、輸入框不能編輯,並且表單不能獲得輸入框內的值

<

input

value

="不可修改"

disabled

="disabled"

type

="text"

/>//:字型顏色為灰體

11、輸入框禁止輸入法:

<

input

onpaste

="return false"

style

="ime-mode:disabled"

>

在HTML中限制input 輸入框只能輸入純數字

限制 input 輸入框只能輸入純數字 1 onkeyup value value.replace d g,使用 onkeyup 事件,有 bug 那就是在中文輸入法狀態下,輸入漢字之後直接回車,會直接輸入字母 2 onchange value value.replace d g,使用 onchan...

在HTML中限制input 輸入框只能輸入純數字

1 onkeyup value value.replace d g,使用onkeyup事件,有bug,那就是在中文輸入法狀態下,輸入漢字之後直接回車,會直接輸入字母 2 onchange value value.replace d g,使用onchange事件,在輸入內容後,只有input喪失焦點時...

HTML中input輸入框動態模糊匹配

html中的input輸入框根據後台返回的動態模糊匹配輸入的內容,可以選擇,也可以輸入,此處是使用的是html5新增的標籤datalist來實現,不需要外掛程式,頁面載入完時直接將後台查詢到的所有值賦給datalist,還有一種是輸入框中有改變時都呼叫介面向後台查詢一次,返回給前台,這裡先不做介紹。...